我使用JNI编译主要的跨平台库,使用CMake编译库路径中的所有库。
使用变量CMAKE_BUILD_TYPE = Debug工作正常,但使用Release,在启动我的Android应用程序时,抛出:
我使用傻瓜Android.mk启动我的Android项目只是为了安装在libs / armeabi-v7a中并正确链接库:
05-27 08:35:35.194:E / dalvikvm(10366):dlopen(“/ data / app-lib / com.stackoverflow.project-2 / libandroid-fooa.so”)失败:dlopen失败:“ /data/app-lib/com.stackoverflow.project-2/libandroid-fooa.so“有意想不到的e_type:1
05-27 08:35:35.204:E / AndroidRuntime(10366):进程:com.stackoverflow.project-2,PID:10366 05-27 08:35:35.204:E / AndroidRuntime(10366):java.lang.UnsatisfiedLinkError:dlopen失败:“/ data / app-lib / com.stackoverflow.project-2 / libandroid-fooa.so”有意外的e_type :1 05-27 08:35:35.204:E / AndroidRuntime(10366):at java.lang.Runtime.loadLibrary(Runtime.java:364)
Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android-opencvcamera_4_4-prebuilt
LOCAL_SRC_FILES := ../../../resources/lib/opencv/android/OpenCV-2.4.8-android-sdk/sdk/native/libs/armeabi-v7a/libnative_camera_r4.4.0.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := android-opencvcamera_4_2-prebuilt
LOCAL_SRC_FILES := ../../../resources/lib/opencv/android/OpenCV-2.4.8-android-sdk/sdk/native/libs/armeabi-v7a/libnative_camera_r4.2.0.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := android-foo-prebuilt
#LOCAL_SRC_FILES := ../../../../build/Android/trunk/lib/libfoo_d.so // work in debug
LOCAL_SRC_FILES := ../../../../build/Android/trunk/lib/libfoo.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := android-fooa-prebuilt
#LOCAL_SRC_FILES := ../../../../build/Android/trunk/lib/libandroid-fooa_d.so // work in debug
LOCAL_SRC_FILES := ../../../../build/Android/trunk/lib/libandroid-fooa.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := android-void
LOCAL_SRC_FILES := android-void.cpp // Has no code, generated by eclipse native option
include $(BUILD_SHARED_LIBRARY)
在调试中使用android-ndk-r9d和eclipse启动命令:
$(ANDROID_NDK)/ ndk-build NDK_DEBUG = 1
工作正常。停在断点处,但是当我停在它们时不提供调试信息,我不知道这是否重要!
发布时:
$(ANDROID_NDK)/ ndk-build NDK_DEBUG = 0
我在Java文件中加载库:
// Load Native Libraries
// =========================================================================
static
{
//System.loadLibrary("foo_d");
//System.loadLibrary("android-fooa_d");
System.loadLibrary("foo");
System.loadLibrary("android-fooa");
}
出现链接问题。
答案 0 :(得分:2)
我发现了问题,但我不知道为什么会这样。当我启动应用程序时,ndk-build安装在libs / armeabi-v7a库中,但是android-fooa.so是错误的,将大小从原来的5.6 Mb改为$(LIBRARY_PATH)到< libs / armeabi-v7a中500 kbs,因此在启动过程中库已损坏。
我已经解决了这个问题,手动复制了库,并避免在eclipse中使用ndk-build。如果我使用ndk-build,那么库将再次被破坏。
<强>更新强>
使用CMake
进行编译并将库安装到libs / armeabi-v7a中会导致问题。所以我将带有CMake的预构建库安装到jni / prebuilt中,并将它们添加到Android.mk
对每个预建的库使用这些喜欢必须有效:
# Prebuilt lib code
include $(CLEAR_VARS)
LOCAL_MODULE := android-foo
LOCAL_SRC_FILES := prebuilt/libandroid-foo.so
include $(PREBUILT_SHARED_LIBRARY)