Reputation: 376
I took the android native activity sample from Android Studio and replaced the app glue implementation by my own implementation of native activity.
So here is my Cmake file which almost the same as in the sample:
cmake_minimum_required(VERSION 3.4.1)
#my implementation
add_library(android-impl STATIC
C:/android_libs/native-impl/Activity.cpp
)
# now build app's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(my-app SHARED
main.cpp
)
#add include directories
target_include_directories(my-app PRIVATE
C:/android_libs/native-impl/)
# add lib dependencies
target_link_libraries(my-app
android
android-impl
EGL
GLESv1_CM
log)
And I also specified in the Android manifest file the name of my shared lib like this:
<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="my-app" />
It all compiles, but when I run on my device it instantly throws an error:
Caused by: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.nativetest.myapp-1/lib/arm/libmy-app.so
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nativetest.myapp/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.nativetest.myapp-2/lib/arm/libmy-app.so
I don't understand because I have copied the same Cmake file from the sample provided for native activity and just replaced app glue with my implementation, and used different name for my shared library.
Here are the files from the sample that I used: Cmakelist.txt AndroidManifest.xml
Is there something else that I need to modify ?
Upvotes: 2
Views: 1047
Reputation: 376
After hours of comparing my code to the sample code I have finally figured out what was wrong, which was caused by a lack of .. one line of code.
The problem seems to be related to the native activity implementation, which uses callbacks, since I am not well understanding what's going on, I'll link to the only explanation I've found: http://blog.beuc.net/posts/Make_sure_glue_isn__39__t_stripped/
So the solution is simply to have an empty function or whatever in your native activity implementation (which is app glue in the sample code), and you need to call it through your shared lib, your main code.
If someone would like to explain more in detail, or give a nicer alternative to this workaround it would be welcome.
Upvotes: 2