Having spent hours and hours searching for a solution to my problem and browsing through various forums (including this one), I finally decided to ask my question, hoping that he did not receive a complete answer elsewhere.
I am trying to build a rather complex architecture:
- I have C sources that I compile in the section shares static libraries (.a)
- I use them through JNI in the module library.
- I want to use this library in an application project.
At first, I successfully completed the following tests - I have already managed to create a library of modules without NDK and compile it using the application. - I also managed to use static libraries and JNI directly in the application, but
I do not perform the next step: - The combination of JNI inside the module and the application that calls the module classes does not work.
I think the problem is with enabling aar, because I cannot find exploded-aar in the build directory of my application, while aar is in the build / output directory of the library. In addition, all previous tests (including the use of JNI were successful).
I do not use an experimental model because it is experimental and there are known limitations with static libraries.
The structure of my project:
- App - src - main - java - activity - bar - src - main - java - class - jni - include - *.h - libs - abis... - libmod1.a - libmod2.a Android.mk Application.mk bar.c bar.h
The build.gradle application looks like this:
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.0" defaultConfig { applicationId "com.test.foo" minSdkVersion 10 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { debuggable false jniDebuggable false minifyEnabled false } unsigned { debuggable false jniDebuggable false minifyEnabled false } debug { debuggable true jniDebuggable true minifyEnabled false } } productFlavors { x86 { ndk { abiFilter "x86" } } mips { ndk { abiFilter "mips" } } armv7 { ndk { abiFilter "armeabi-v7a" } } arm { ndk { abiFilter "armeabi" } } fat } project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9] android.applicationVariants.all { variant -> variant.outputs.each { output -> output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + defaultConfig.versionCode } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar','*.aar']) compile project( ":bar" ) }
The build.gradle module is as follows:
apply plugin: 'com.android.library' android { compileSdkVersion 23 buildToolsVersion "23.0.0" defaultConfig { minSdkVersion 10 targetSdkVersion 23 versionCode 1 versionName "1.0" ndk { moduleName "module" } } buildTypes { release { debuggable false jniDebuggable false minifyEnabled false } unsigned { debuggable false jniDebuggable false minifyEnabled false } debug { debuggable true jniDebuggable true minifyEnabled false } } productFlavors { x86 { ndk { abiFilter "x86" } } mips { ndk { abiFilter "mips" } } armv7 { ndk { abiFilter "armeabi-v7a" } } arm { ndk { abiFilter "armeabi" } } fat } sourceSets.main { jniLibs.srcDir 'src/main/libs' jni.srcDirs = [] } task ndkBuild(type: Exec) { commandLine android.ndkDirectory.getAbsolutePath()+'/ndk-build', '-C', file('src/main').absolutePath } tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn ndkBuild } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
My Android.mk inside the module jni directory: LOCAL_PATH: = $ (call my-dir)