I’ve been searching all over the place this morning trying to figure out what’s wrong but haven’t found an answer that works for me.
I have a sub-project which generates an AAR file and a set of JNI libs. When I examine this AAR I can see my .so files.
I’m generating my APK in another project which has a dependency on the AAR project. However when I run my APK program I always get an UnsatisfiedLinkError because it can’t find my .so files at runtime. If I expand the APK file I can see that they are indeed not present. However in my APK’s build/intermediates/exploaded-aar dir I can see the local version of the AAR files and in the classes.jar file I can see my missing .so libs.
I’m pretty new to Gradle so there’s a lot I’m still coming up to speed on. But I just can’t figure out what the problem is here. Hopefully someone has some suggestions.
Here is my AAR build.gradle:
apply plugin: 'android-library'
apply plugin: 'android-apt'
sourceCompatibility = 1.6
targetCompatibility = 1.6
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
android {
compileSdkVersion 18
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 18
targetSdkVersion 18
versionCode 1
versionName "1.0"
ndk {
moduleName = "usbcamera"
abiFilters = ['armeabi-v7a']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
jni.srcDirs = [] // disalbe NDK auto build (not sure why this is necessary)
jniLibs.srcDir 'src/libs'
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
if (androidNdk != null) {
def ndkDir = androidNdk //android.plugin.ndkFolder
commandLine "$androidNdk/ndk-build",
'-C', file('jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
} else {
doLast {
println '##################'
println 'Skipping NDK build'
println 'Reason: ANDROID_NDK not set.'
println '##################'
}
}
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = androidNdk
commandLine "$ndkDir/ndk-build",
'-C', file('jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
lintOptions {
disable 'InvalidPackage', 'LongLogTag'
}
dependencies {
compile project(':HsosSdk')
}
}
repositories {
mavenCentral()
}
dependencies {
// annotation processors for the pre-compile phase
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
// annotation processors for the compile phase
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'javax.inject:javax.inject:1'
compile 'com.squareup:javawriter:2.5.1'
}
artifacts.add("default", file('build/outputs/aar/UdaDrivers-release.aar'))
clean.doFirst {
delete 'bin/udadrivers.jar'
}
==============================================
Here is my APK build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
sourceCompatibility = 1.6
targetCompatibility = 1.6
android {
compileSdkVersion 18
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 18
targetSdkVersion 18
versionCode 1
versionName "1.0"
ndk {
abiFilters = ['armeabi-v7a']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
sourceSets {
main.manifest.srcFile 'AndroidManifest.xml'
main.java.srcDirs = ['src']
}
lintOptions {
disable 'InvalidPackage', 'LongLogTag'
}
dependencies {
compile project(':UdaDrivers')
}
dexOptions {
preDexLibraries = true
}
project.tasks.withType(com.android.build.gradle.tasks.Dex) {
// additionalParameters=['--core-library']
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral()
}
sourceSets {
main.output.classesDir = 'bin/classes'
}
dependencies {
// annotation processors for the pre-compile phase
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
// annotation processors for the compile phase
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'javax.inject:javax.inject:1'
compile 'com.squareup:javawriter:2.5.1'
// remote libraries
compile 'org.jgroups:jgroups:3.5.1.Final'
compile project(':Algorithms')
}