【问题标题】:java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libssl.so"java.lang.UnsatisfiedLinkError:dlopen 失败:库“/system/lib/libssl.so”
【发布时间】:2017-12-28 05:31:08
【问题描述】:

我正在尝试在我的 android 应用程序中加载 OpenSSL .so 文件,但它抛出 UnsatisfiedLinkError。

我的代码:

public class MainActivity extends AppCompatActivity {

static {
    System.loadLibrary("ssl");
    System.loadLibrary("crypto");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}}

例外:

12-28 10:53:41.753 12254-12254/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.ndk.test.app, PID: 12254
                                               java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib/libssl.so" needed or dlopened by "/system/lib/libnativeloader.so" is not accessible for the namespace "classloader-namespace"
                                                   at java.lang.Runtime.loadLibrary0(Runtime.java:977)
                                                   at java.lang.System.loadLibrary(System.java:1567)
                                                   at com.ndk.test.app.MainActivity.<clinit>(MainActivity.java:11)
                                                   at java.lang.Class.newInstance(Native Method)
                                                   at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2839)
                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
                                                   at android.app.ActivityThread.-wrap14(ActivityThread.java)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                   at android.os.Looper.loop(Looper.java:154)
                                                   at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

CMakeList.txt

          cmake_minimum_required(VERSION 3.4.1)

            # configure import libs
             set(distribution_DIR ${PROJECT_SOURCE_DIR}/src/main/cpp)

             add_library(lib_crypto SHARED IMPORTED)
             set_target_properties(lib_crypto PROPERTIES IMPORTED_LOCATION
                        ${distribution_DIR}/libs/libcrypto.so)

             add_library(lib_ssl SHARED IMPORTED)
             set_target_properties(lib_ssl PROPERTIES IMPORTED_LOCATION
                         ${distribution_DIR}/libs/libssl.so)

        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

        add_library( # Sets the name of the library.
                       native-lib

                     # Sets the library as a shared library.
                       SHARED
                     # Provides a relative path to your source file(s).
                       src/main/cpp/native-lib.cpp           
                   )


         find_library( # Sets the name of the path variable.
                     log-lib

                       # Specifies the name of the NDK library that
                       # you want CMake to locate.
                     log )

          target_include_directories(native-lib PRIVATE
                       ${distribution_DIR}/include
                       ${distribution_DIR}/include)

          target_link_libraries( # Specifies the target library.
                        native-lib
                        android
                        lib_crypto
                        lib_ssl

                        # Links the target library to the log library
                        # included in the NDK.
                        ${log-lib} )

这在我的代码和异常之上。我还在 CMakeList.txt 中导入了 .SO(s),但我无法找到问题的确切问题,因为我还将 .SO(s) 放在了 libs 文件夹中.

请给我一些解决方案。

【问题讨论】:

    标签: android cmake android-ndk openssl


    【解决方案1】:

    我的错,我通过添加 ${ANDROID_ABI} 解决了这个问题,我忘记将 .SO(s) 放在 ABI 文件夹中。

    set(distribution_DIR ${PROJECT_SOURCE_DIR}/src/main/cpp/${ANDROID_ABI})
    

    【讨论】:

      猜你喜欢
      • 2020-07-28
      • 2018-07-27
      • 2015-04-16
      • 1970-01-01
      • 2019-02-04
      • 2017-04-11
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多