[Xavier Hallade] Mastering the NDK with Android Studio 1.3+ and the gradle-experimental plugin
Presentation from GDG DevFest Ukraine 2015 - the biggest Google related event in the country. October 23-24, Lviv. Learn more at http://devfest.gdg.org.ua/
history of Android Studio support of the NDK What we can do now with Android Studio Migrating to the gradle-experimental plugin Configuring your projects Q&A
return Java primitives and objects jint xxx(JNIEnv* env, jclass cls, …) use a specific function name: Java_com_example_hellojni_MainActivity_method or do a manual registration using JNIEnv->RegisterNatives()
optimized code for all target ABIs You can also pass APP_ABI variable to ndk-build, and specify each ABI: ndk-build APP_ABI=x86 all32 and all64 are also possible values. ndk-build(.cmd) Build ARM64 libs Build x86_64 libs Build mips64 libs Build ARMv7a libs Build ARMv5 libs Build x86 libs Build mips libs
by System.loadLibrary() 1. C/C++ functions ó Java native methods 2. DVM/ART encounters a call to a native method 1. its C/C++ implementation is executed 2. then, Java code execution goes on * android.app.NativeActivity/ native_activity.h allow to develop without having Java code inside the app.
• December 2013: gradle 0.7.3 - sort of support for the NDK • December 2014: Eclipse ADT no longer in development • May 2015: Integration of CLion announced at Google I/O • July 2015: beta available! • October 2015: still quite WIP (-experimental), but usable!
+ most configurable solution (using Android.mk/Application.mk) + supports generating split APKs with proper version codes - No C/C++ code editing/debugging within Android Studio
code editing within Android Studio + usual Android.mk/Application.mk support (with full native dependencies support) - it’s experimental - can’t generate split APKs with proper version codes - can’t debug from Android Studio
cppFlags ldLibs ldFlags abiFilters stl renderscriptNdkMode debuggable } In the model, but not yet in the DSL: cIncludeDirs cppIncludeDirs cDefines cppDefines
"x86" ndk.ldFlags += "-L${file("src/main/jni/prebuilts/x86")}".toString() } } build.gradle Please don’t do this, as version codes can’t be properly handled.
multiple APKs for the same application. What compatible APK will be chosen for a device entirely depends on the android:versionCode If you have multiple APKs for multiple ABIs, best is to simply prefix your current version code with a digit representing the ABI: 2310 3310 6310 7310 You can have more options for multiple APKs, here is a convention that will work if you’re using all of these: x86 ARMv7 ARM64 X86_64