我一直致力于使用打包在.aar文件中的外部库的应用程序。在gradle文件中,我只需要添加
compile project(':empalink-2.0')
到目前为止它工作正常。现在我想添加libSVM
库的一个端口,这样我就可以将jni
目录复制到我的app/src/main
中,然后从他们的gradle文件中添加一些代码,最终会像这样:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.csic.iiia.ActivityRecognition"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
moduleName "jnilibsvm" // <-- This is the name of my C++ module!
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'src\\main\\libs'
jni.srcDirs = []
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir\\ndk-build.cmd",
'-C', file('src\\main\\jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir\\ndk-build.cmd",
'-C', file('src\\main\\jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.loopj.android:android-async-http:1.4.6'
compile project(':empalink-2.0')
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'org.apache.commons:commons-math3:3.6.1'
}
添加的部分是defaultConfig.ndk
和build/cleanNative
内容。
现在,在尝试执行应用程序时,收到以下错误:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.csic.iiia.ActivityRecognition-1/base.apk"],nativeLibraryDirectories=[/data/app/com.csic.iiia.ActivityRecognition-1/lib/arm64, /data/app/com.csic.iiia.ActivityRecognition-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libempac.so"
lilbempac.so
是.aar文件中的.so
文件,该文件正常工作,直到我将libSVM
添加到项目中。我想启用NDK编译会以某种方式影响与外部依赖关系:empalink-2.0
的链接。
答案 0 :(得分:2)