Issue
I'm currently working with a NDK Project that uses shared libraries. And I have two shared libraries to integrate: libsatprotocol.so and libsat-tanca.so.
So I added to my Android.mk these libraries so I could make a wrapper. For libsatprotocol everything is working fine. But for libsat-tanca, I get a crash on 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)
So the weird thing is that this path in my computer path for the library, and I have no clue from where it is getting it. If I remove the libsat-tanca of the dependencies, it works fine (in libsatprotocol).
Here are my 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)
apply plugin: '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'
}
Any idea why it is linking just the libsat-tanca.so with my PC path?
Solution
There are two things that look wrong to me here, but I don't know for sure that this is what is causing the link path to be incorrect.
1) The $(SYSROOT) variable in this line points to a path on your machine, right?
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -lz -llog
If linking to zlib and the log libraries is the goal, you can just use the following and the build will do the right thing:
LOCAL_LDLIBS += -lz -llog
2) Why is the following line in your Application.mk? You shouldn't need this, but I don't think it's likely to cause the link problem.
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libsatprotocol.so $(TARGET_ARCH_ABI)/libsat-tanca.so
Answered By - Francesca Nannizzi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.