Manual compilation of native activity and 'android_native_app_glue'

66 views
Skip to first unread message

Armen Avetisyan

unread,
Aug 29, 2016, 10:42:17 AM8/29/16
to android-ndk
Hi,

I am trying to setup the build completely via command line, however there is one issue that drives me insane:
  • Compilation of native-activity.so goes well, but upon loading the app crashes.
  • It works fine with Google's pre-compiled armeabi-v7a libnative-activity.so.
Because of the latter fact, I can tell for sure that 
  • either the creation of libandroid_native_app_glue.a is erroneous
  • or the creation of native-activity.so
Here is the simplified cmake snippet that creates the shared library. I am sorry for the numerous flags.

add_custom_command(OUTPUT lib/armeabi-v7a/libnative-activity.so
 COMMAND $
{CXX} -shared -Wl,-soname,libnative-activity.so
 
-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now
 
--sysroot=/usr/local/Cellar/android-ndk/r12b/platforms/android-23/arch-arm
 
-Wl,--build-id -L/usr/local/Cellar/android-ndk/r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a
 
-lgnustl_static -no-canonical-prefixes -llog -landroid -lEGL -lGLESv1_CM
 jni
/main.o jni/libandroid_native_app_glue.a -o $@)

add_custom_command
(OUTPUT jni/main.o
 COMMAND $
{CXX} -fPIC -DANDROID -DANDROID_NDK -fno-rtti -fno-exceptions
 
--sysroot=/usr/local/Cellar/android-ndk/r12b/platforms/android-23/arch-arm
 
-I/usr/local/Cellar/android-ndk/r12b/sources/cxx-stl/gnu-libstdc++/4.9/include
 
-I/usr/local/Cellar/android-ndk/r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include
 
-ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv7-a
 
-mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing
 
-finline-limit=64 -std=c++11 -I /usr/local/Cellar/android-ndk/r12b/sources/android/native_app_glue
 
-c jni/main.cpp -o jni/main.o)

add_custom_command
(OUTPUT jni/libandroid_native_app_glue.a
 COMMAND $
{AR} rcs $@ jni/android_native_app_glue.o)

add_custom_command
(OUTPUT jni/android_native_app_glue.o
 COMMAND $
{CC} -march=armv7-a -c ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c -o jni/android_native_app_glue.o)


NoAngel

unread,
Sep 5, 2016, 11:16:17 AM9/5/16
to android-ndk
Hi,
Did u try to compile native_app_glue from source located in <your ndk path>/sources/android/native_app_glue.
It's so small one c, one h these 2, take them, copy to your project, add them to your build, they should be work. Don't need to compile them in separate so, link them statically, only few kbytes add to Your binary.
Reply all
Reply to author
Forward
0 new messages