In our companywe are developing an Android SDK that contains both Java and the native part. We compile the SDK in AAR format, which contains all the resources, Java classes, and native bits. According to the AAR specification, native libraries must be located inside the jni folder inside the AAR package. Since the current gradle plugin does not support extended use cases of NDK, and since we have a very mature Android.mk file that has developed over 3 years of development, we prepare AAR by calling a special shell script from the gradle task. This script shell creates the NDK using the ndk-build command, and the task that runs this script is set as a dependency of the javaCompile task (there are several variants of our code, and each taste has its own rules for NDK, which are preloaded from the definition file,and then passed to ndk-build as command line arguments).
Finally, when everything compiles, we have the Copy task, which copies our own libraries to the jni folder inside build / intermediates / bundles (the folder that eventually becomes archived in AAR). This worked correctly until we updated our project to use the gradle plugin v1.5.0.
In version 1.5.0, something called the Transform API was added to the plugin. Although we do not use this, this Transform step does some conversion of the native libs to the transformNative_libsWithSyncJniLibsForFlavorNameBuildTypeName task , which happens somewhere after we already copied our libraries to the jni folder and caused the deletion of all the data in the jni folder. This finally leads to the fact that AAR does not contain native libraries and crashes as soon as native methods are required.
, project.tasks[taskName], , , jni.
, , gradle - (, NDK) NDK.
, , (?), ( gdb AAR, jniDebuggable ).
- , API ? ndk-build shellscript gradle - NDK ( ++ Android Studio, , JNI).