With the release of Android Studio 2.2, there is now a built-in way to execute complex ndk builds using externalNativeBuild. I have been having trouble getting this to work with my enterprise project which has some java plugins and c++ plugins.
Prior to Android Studio 2.2, I had my project setup to perform the ndk-build for the c++ plugins on the command line which uses an Android.mk and Application.mk, the task in gradle looked like this:
task ndkBuild(type: Exec) { commandLine getNdkBuildCmd(), '-C', file('src/main/jni').absolutePath, '-j', Runtime.runtime.availableProcessors(), "NDK\_LIBS\_OUT=$jniLibsDir", 'all', 'NDK\_DEBUG=1' dependsOn 'generateLuaBytecodes' doFirst { println '== ndkBuild ==' } }
GenerateLuaByteCodes is a task that runs lua2c.sh to create the c++ plugin.c file.
After upgrading to 2.2, I tried to use the externalNativeBuild configuration to accomplish the same thing, and this is what I came up with:
defaultConfig { externalNativeBuild { ndkBuild { arguments "NDK\_LIBS\_OUT=$jniLibsDir", "-j$numProcs", "all" abiFilters "armeabi-v7a" } } } externalNativeBuild{ ndkBuild{ path "src/main/jni/Android.mk" } }
I made it so that the externalNativeBuild task depends on generateLuaByteCodes.
The build order for assembleDebug goes a little something like this:
- build java plugins
- build c++ plugins
- compile lua
- certify build
- bundle/package/assemble apk per the built-in functionality
Currently, the build is succeeding, but it is crashing on startup with ExceptionInInitializerError, UnsatisfiedLinkError (see attached log for stacktraces). Given that the app works on 2.2 using the ndk-build command, and does not with externalNativeBuild, it seems like something must be setup wrong. I want to use externalNativeBuild because it gets all of the c++ into the android studio project for editing and debugging just like in xCode.
Additional Info/Tool versions:
- Completely clean build
- Corona Enterprise build 2016.2954
- Android NDK r12b
- SDK target 24, min 16, build tools 24.0.2 (all projects/modules)
- Android Studio embedded Java 8
- Gradle version 2.14.1
- Android Plugin version 2.2.0
- c++_static (clang) runtime
If anyone has had success with externalNativeBuild, or can point me in the right direction, I would greatly appreciate it.