简体   繁体   English

尝试加载预编译的 .so Android NDK(异常 java.lang.UnsatisfiedLinkError: dlopen failed: library)

[英]Try to load precompiled .so Android NDK (Exception java.lang.UnsatisfiedLinkError: dlopen failed: library)

I try to build an Android Project (ndk-build).我尝试构建一个 Android 项目 (ndk-build)。

I´d like to use a precompiled library in my project.我想在我的项目中使用预编译库。 (libdemo.so) (libdemo.so)

Android.mk:安卓.mk:

APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions
APP_ABI=armeabi armeabi-v7a

Application.mk:应用程序.mk:

LOCAL_PATH := $(call my-dir)
TARGET_ARCH_ABI := armeabi-v7a

include $(CLEAR_VARS)
LOCAL_MODULE := libdemo
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libdemo.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := native-lib
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_SHARED_LIBRARIES := libdemo
include $(BUILD_SHARED_LIBRARY)

MainActivity:主要活动:

android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
     static {
        System.loadLibrary("demo");
        System.loadLibrary("native-lib");
    }

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

        TextView tv = (TextView) findViewById(R.id.sample_text);
        Log.d("TAG", stringFromJNI());
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();
}

But I get the following exception on build:但是我在构建时遇到以下异常:

java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/John/Documents/Apps/LibTest/app/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/libdemo.so" not found

The file exists on the provided path.该文件存在于提供的路径中。 I think the path at all isn´t correct.我认为路径根本不正确。 Why is there the path from my desktop pc?为什么我的台式电脑有路径? There should be a path from my device or?我的设备应该有路径还是?

Anyone here to help?有人来帮忙吗? Thanks谢谢

I solved the question by myself.我自己解决了这个问题。

I don´t knew that ndk-build isn´t processed automatically.我不知道 ndk-build 不是自动处理的。 I had go to my project folder (folder where jni is present) and does ndk-build manually.我已经转到我的项目文件夹(存在 jni 的文件夹)并手动执行 ndk-build。

After that the libs are compiled and copied automatically in the /libs folder.之后,库会自动编译并复制到 /libs 文件夹中。

Now just build and run the app as usual and everything is fine.现在只需像往常一样构建和运行应用程序,一切都很好。

In my case this was caused by missing SONAME tag on the generated shared library.就我而言,这是由于生成的共享库上缺少SONAME标记造成的。 When this tag is missing, the Android build process will use the absolute path to the library instead of the device-specific path.如果缺少此标记,Android 构建过程将使用库的绝对路径而不是特定于设备的路径。

One has to explicitly specify the SONAME either via -soname or -install_name (macOS-specific) parameter to the linker.必须通过-soname-install_name (特定于 macOS 的)参数向链接器显式指定 SONAME。

For instance, this can happen when building shared libs from Go source, as mentioned in https://github.com/golang/go/issues/17807\\#issuecomment-259930881 .例如,从 Go 源构建共享库时可能会发生这种情况,如https://github.com/golang/go/issues/17807\\#issuecomment-259930881 中所述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Opencv Android:java.lang.UnsatisfiedLinkError:dlopen失败:无法加载库“libopencv_java.so” - Opencv Android: java.lang.UnsatisfiedLinkError: dlopen failed: could not load library “libopencv_java.so” java.lang.UnsatisfiedLinkError:dlopen失败:找不到库“ libutils.so” - java.lang.UnsatisfiedLinkError: dlopen failed: library “libutils.so” not found java.lang.UnsatisfiedLinkError:dlopen失败:找不到库“ libpthread.so.0” - java.lang.UnsatisfiedLinkError: dlopen failed: library “libpthread.so.0” not found java.lang.UnsatisfiedLinkError:dlopen 失败:找不到库“../../lib/libopencv_core.so” - java.lang.UnsatisfiedLinkError: dlopen failed: library "../../lib/libopencv_core.so" not found java.lang.UnsatisfiedLinkError:dlopen失败:.so库是64位而不是32位 - java.lang.UnsatisfiedLinkError: dlopen failed: .so library is 64-bit instead of 32-bit Android NDK java.lang.UnsatisfiedLinkError错误 - Android NDK java.lang.UnsatisfiedLinkError error android ndk java.lang.UnsatisfiedLinkError:nativeStart - android ndk java.lang.UnsatisfiedLinkError: nativeStart NDK Android Studio中的java.lang.UnsatisfiedLinkError - java.lang.UnsatisfiedLinkError in NDK android studio java.lang.UnsatisfiedLinkError:nativeStart android NDK - java.lang.UnsatisfiedLinkError: nativeStart android NDK 线程“ main”中的异常java.lang.UnsatisfiedLinkError:无法加载库 - Exception in thread “main” java.lang.UnsatisfiedLinkError: Unable to load library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM