java.lang.UnsatisfiedLinkError:dlopen失败:库“/system/lib/libssl.so”

问题描述 投票:0回答:1

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

MyCode:

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个回答
0
投票

我的坏,我通过添加$ {ANDROID_ABI}来解决它,我忘了将.SO放在ABI文件夹中。

set(distribution_DIR ${PROJECT_SOURCE_DIR}/src/main/cpp/${ANDROID_ABI})
© www.soinside.com 2019 - 2024. All rights reserved.