本文介绍了java.lang.UnsatisfiedLinkError:dlopen失败:无法找到符号"_ZNSt6__ndk17codecvtIcc9mbstate_tE2idE";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ndk-build构建静态库并成功编译为* .so,但是在android模拟器中运行时会抛出运行时错误.错误是

I use ndk-build to build a static library and compile to a *.so successfully, but Runtime error is thrown when runs in android simulator. The error is

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: org.example.kotlin.mixed, PID: 31185
                  java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZNSt6__ndk17codecvtIcc9mbstate_tE2idE" referenced by "/data/app/org.example.kotlin.mixed-2/lib/x86/libtest.so"...
                      at java.lang.Runtime.loadLibrary(Runtime.java:372)
                      at java.lang.System.loadLibrary(System.java:1076)
                      at com.bytedance.lark.sdk.Sdk.<init>(Sdk.kt:15)
                      at org.example.kotlin.mixed.MyApplication.onCreate(MyApplication.kt:12)
                      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
                      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
                      at android.app.ActivityThread.-wrap1(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我发现符号_ZNSt6__ndk17codecvtIcc9mbstate_tE2idE出现在我构建的静态库中.我在源代码中找不到ndk的引用.我不确定ndk-build是否将此符号添加到静态库中.

And I find symbol _ZNSt6__ndk17codecvtIcc9mbstate_tE2idE appears on the static library I build. I can not find reference of ndk in my source code. I am not sure if the ndk-build add this symbol to the static lib.

ndk-build配置在这里.

the ndk-build config goes here.

Application.mk

Application.mk

APP_ABI := x86

APP_PLATFORM := android-21 // I change this to android-14, also not work
APP_STL:=c++_static
APP_CPPFLAGS:=-std=c++11 -fexceptions -frtti  -DANDROID -DDEBUG

NDK_TOOLCHAIN_VERSION := clang

Android.mk

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include ../uuid/Android.mk
include mylib.mk

mylib.mk

LOCAL_PATH := $(call my-dir)

MYLIB_CSOURCES := \
  // my source code

MYLIB_INCLUDES := \
  $(LOCAL_PATH)/../uuid/include \
  $(LOCAL_PATH)/../../../../../lib/rapidjson/include \
  $(LOCAL_PATH)/../../../../../src

###
### Build mylib.a
###

include $(CLEAR_VARS)

LOCAL_MODULE := mylibc++

LOCAL_SRC_FILES := \
    $(addprefix ../../../../../src/,$(MYLIB_CSOURCES))

LOCAL_C_INCLUDES := $(MYLIB_INCLUDES)

LOCAL_CFLAGS += -DANDROID -DDEBUG -D__ANDROID__

LOCAL_WHOLE_STATIC_LIBRARIES := uuid

include $(BUILD_STATIC_LIBRARY)

android构建配置:

android build config:

android {
    compileSdkVersion 23
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    sourceSets.main {
        jni.srcDirs = []
        jniLibs.srcDir 'libs'
    }
}

推荐答案

符号 _ZNSt6__ndk17codecvtIcc9mbstate_tE2idE (表示 std :: __ ndk1 :: codecvt :: id )可用在 libc ++ _ shared.so 中.

The symbol _ZNSt6__ndk17codecvtIcc9mbstate_tE2idE (which means std::__ndk1::codecvt::id) is available in libc++_shared.so.

如果运行时环境(仿真器)低于API 21,则 必须 从Java显式加载此库,然后再加载 libtest.so .

If your runtime environment (emulator) is lower than API 21, you must explicitly load this library from Java, before you load libtest.so.

libc ++ _ shared.so 也应与 libtest.so 一起打包到APK中.确保它存在于 libs/x86 中以及其他相关的ABI中.

libc++_shared.so should also be packed into the APK together with libtest.so. Make sure that it is present in libs/x86 and also for other relevant ABIs.

在Android Studio中,您可以让gradle为您构建NDK库,它将处理必要的依赖项.

In Android Studio, you can let gradle build the NDK libraries for you, and it will take care of the necessary dependencies.

这篇关于java.lang.UnsatisfiedLinkError:dlopen失败:无法找到符号"_ZNSt6__ndk17codecvtIcc9mbstate_tE2idE";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 22:07