[英]Android NDK Exception failed: dlopen failed: cannot locate symbol “_ZN7Tangram11setPositionEdd” referenced by “libtangram.so”
I am trying to run a demo application of a Library in which android ndk is integrated. 我正在尝试运行集成了android ndk的Library的演示应用程序。 I have imported this code in Android studio and also downloaded ndk and linked it with project.
我已将此代码导入Android Studio,还下载了ndk并将其与项目链接。 Code compiles and build succesfully.
代码编译并成功构建。 It gives crash with exception "exception ljava lang unsatisfiedlinkerror thrown while initializing" "failed: dlopen failed: cannot locate symbol "_ZN7Tangram11setPositionEdd" referenced by "libtangram.so"..."
它使崩溃,并带有异常“初始化时引发异常ljava lang unsatisfiedlinkerror”“失败:dlopen失败:找不到由“ libtangram.so”引用的符号“ _ZN7Tangram11setPositionEdd” ...“
Application.mk: Application.mk:
APP_STL := c++_shared
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a x86 mips
APP_PLATFORM := android-19
Android.mk: Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := tangram
LOCAL_SRC_FILES := jniExports.cpp jniGenerated.cpp platform_android.cpp
LOCAL_LDLIBS := -llog
LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
include $(BUILD_SHARED_LIBRARY)
Module Gradle File: 模块Gradle文件:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = GROUP
version = VERSION_NAME
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
jni.srcDirs = []
assets.srcDirs = ['core/resources']
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:/Users/Administrator/AppData/Local/Android/android-ndk-r10e/ndk-build.cmd",
'NDK_PROJECT_PATH=build/intermediates/ndk',
'NDK_LIBS_OUT=jniLibs',
'APP_BUILD_SCRIPT=jni/Android.mk',
'NDK_APPLICATION_MK=jni/Application.mk'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
// Add gdb server to apk
afterEvaluate {
Sync packageTask = project.getTasks().findByName("packageReleaseJniLibs")
if (packageTask) { packageTask.include(['**/gdbserver', '**/gdb.setup']) }
packageTask = project.getTasks().findByName("packageDebugJniLibs")
if (packageTask) { packageTask.include(['**/gdbserver', '**/gdb.setup']) }
}
dependencies {
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'xmlpull:xmlpull:1.1.3.1'
}
apply from: file('gradle-mvn-push.gradle')
In Java class load libraries: 在Java类加载库中:
static {
System.loadLibrary("c++_shared");
System.loadLibrary("tangram");
}
I google this issue and in these posts Link1 Link2 Link3 Link4 it is mentioned that it may be the issue of compiling at api 21 or newer and running it on older devices. 我用谷歌搜索这个问题,在这些文章Link1 Link2 Link3 Link4中提到,这可能是在api 21或更高版本上编译并在较旧的设备上运行它的问题。 But i have mentioend APP_PLATFORM := android-19 in my Application.mk and getting this exception.
但是我Application.mk中有mentioend APP_PLATFORM:= android-19并得到了这个异常。
Any Help? 有帮助吗?
It looks like you tried to compile the tangram project from your own custom ndk-build as opposed to their recommended build process ( https://github.com/tangrams/tangram-es#android ). 似乎您尝试从自己的自定义ndk-build而不是其建议的构建过程( https://github.com/tangrams/tangram-es#android )编译tangram项目。 Use their build process with
make
to create the libtangram.so file, and then copy that .so file into your native libraries directory for your app. 将其生成过程与
make
一起使用,以创建libtangram.so文件,然后将该.so文件复制到应用程序的本机库目录中。
The reason it can't find those symbols is because you aren't including the appropriate source files that define those functions when building with the ndk. 找不到这些符号的原因是因为您没有包括使用ndk进行构建时定义这些功能的适当源文件。 By ingnoring undefined symbols, it will compile but won't be able to resolve them at runtime.
通过忽略未定义的符号,它将编译但无法在运行时解析它们。
The symbol you are missing is created from Tangram::setPosition(double, double)
which is defined at https://github.com/tangrams/tangram-es/blob/master/core/src/tangram.cpp#L318 ; 您缺少的符号是从
Tangram::setPosition(double, double)
创建的Tangram::setPosition(double, double)
该文件在https://github.com/tangrams/tangram-es/blob/master/core/src/tangram.cpp#L318定义; however, your Android.mk file doesn't include that source file. 但是,您的Android.mk文件不包含该源文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.