我目前正在使用使用共享庫的NDK項目。我有兩個共享庫來集成:libsatprotocol.so和libsat-tanca.so。Android NDK鏈接器錯誤路徑
所以我添加到我的Android.mk這些庫,所以我可以做一個包裝。對於libsatprotocol,一切工作正常。但對於libsat-TANCA,我得到Android的崩潰:
java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "/home/lucas/Rockspoon/satlib/Android/app/src/main/obj/local/armeabi/libsat-tanca.so" needed by "libsat-jni.so"; caused by library "/home/lucas/Rockspoon/satlib/Android/app/src/main/obj/local/armeabi/libsat-tanca.so" not found
at java.lang.Runtime.loadLibrary(Runtime.java:371)
at java.lang.System.loadLibrary(System.java:989)
因此,奇怪的是,我這條道路在圖書館我的電腦路徑,並沒有從那裏得到它的線索。如果我刪除依賴關係的libsat-tanca,它可以正常工作(在libsatprotocol中)。
這裏是我的Android.mk:
LOCAL_PATH := $(call my-dir)
#LOCAL_ALLOW_UNDEFINED_SYMBOLS=true
include $(CLEAR_VARS)
LOCAL_MODULE := sat-tanca
LOCAL_SRC_FILES := tanca/$(TARGET_ARCH_ABI)/libsat-tanca.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := sat-dimep
LOCAL_SRC_FILES := dimep/$(TARGET_ARCH_ABI)/libsatprotocol.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := sat-jni
LOCAL_SRC_FILES := satlib.c
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -lz -llog
LOCAL_SHARED_LIBRARIES := sat-tanca sat-dimep
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := armeabi #armeabi-v7a mips x86 x86_64
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libsatprotocol.so $(TARGET_ARCH_ABI)/libsat-tanca.so
SATControl.java
static {
System.loadLibrary("sat-jni");
}
的build.gradle(APP)
應用插件:'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.rockspoon.libraries.satlib"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName "sat-jni"
}
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir 'src/main/libs' // This is not necessary unless you have precompiled libraries in your project.
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-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",
'-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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
任何想法爲什麼它只鏈接libsat-tanca.so與我的PC路徑?
這不是造成問題,但它似乎是鏈接器中的錯誤。我的工作環境是使用動態加載器來加載這些庫,並將整個JNI項目結構改爲只注入這樣的文件而不是鏈接。這不是每個人的解決方案,但爲我工作。 –
我會接受你的回答,因爲它適用於這種情況。 –