I have a game that’s written in C++ (libMyGame.so) and a Kotlin activity called "GameActivity" that’s based on NativeActivity. The Kotlin activity hosts the game and the game uses android_native_app_glue to do most of the work.
I’d originally copied android_native_app_glue.c and android_native_app_glue.h into my game project, but I wanted to reference those directly in the NDK home directory so the NDK version can be updated and my game would automatically pick up the new versions.
When I moved android_native_app_glue.c out of the game’s build and put it into the CMake build used by build.gradle, I get ANativeActivity_onCreate not found at runtime.
I did a lot of research and implemented several recommended solutions, but none of them resolved this issue. Below is the current version of my CMakeLists.txt file.
A lot of people said the problem was the symbol being stripped out, but I explicitly tell the linker not to strip it so I don’t understand why the symbol can’t be found at runtime. What can I do to fix this?
cmake_minimum_required(VERSION 3.22.1)
project(MyGame)
set (APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
add_library(app-glue OBJECT ${APP_GLUE_DIR}/android_native_app_glue.c)
target_include_directories(app-glue PUBLIC ${APP_GLUE_DIR})
add_library(native-lib SHARED ./native-lib.cpp)
target_include_directories(native-lib PUBLIC ${APP_GLUE_DIR})
add_library(libMyGame SHARED IMPORTED )
find_library(log-lib log)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
target_link_libraries(native-lib app-glue android ${log-lib} libMyGame)
You need to sign in to view this answers