我的Android項目正在使用具有本機代碼的Android庫項目,並且我從庫使用的本地函數中獲取UnsatisifiedLinkError
。包含庫在Android項目中使用的共享對象
我已經在我的項目的Android.mk文件中包含了庫使用的這些共享對象,並且它們被正確地複製到Eclipse項目的/libs
目錄中,當我構建並出現在目錄的目錄中時跑。找不到的方法應該在libVuforiaTracking.so中。
這是我的Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := QCAR-prebuilt
LOCAL_SRC_FILES = ../../VuforiaTracking/libs/$(TARGET_ARCH_ABI)/libQCAR.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := VuforiaTracking-prebuilt
LOCAL_SRC_FILES = ../../VuforiaTracking/libs/$(TARGET_ARCH_ABI)/libVuforiaTracking.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := MyProject
# The list of shared libraries *modules* this module depends on at runtime.
# This is necessary at link time and to embed the corresponding information
# in the generated file. We reference the prebuilt library defined earlier
# in this makefile.
LOCAL_SHARED_LIBRARIES := QCAR-prebuilt VuforiaTracking-prebuilt
#LOCAL_SRC_FILES := MyProject.cpp
# By default, ARM target binaries will be generated in 'thumb' mode, where
# each instruction are 16-bit wide. You can define this variable to 'arm'
# if you want to force the generation of the module's object files in
# 'arm' (32-bit instructions) mode
LOCAL_ARM_MODE := arm
include $(BUILD_SHARED_LIBRARY)
而這裏的日誌消息:
12-21 09:53:48.220: E/AndroidRuntime(13086): FATAL EXCEPTION: main
12-21 09:53:48.220: E/AndroidRuntime(13086): java.lang.UnsatisfiedLinkError: Native method not found: com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getOpenGlEsVersionNative:()I
12-21 09:53:48.220: E/AndroidRuntime(13086): at com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getOpenGlEsVersionNative(Native Method)
12-21 09:53:48.220: E/AndroidRuntime(13086): at com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getInitializationFlags(VuforiaTrackingActivity.java:293)
12-21 09:53:48.220: E/AndroidRuntime(13086): at com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.onCreate(VuforiaTrackingActivity.java:282)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.Activity.performCreate(Activity.java:5191)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.os.Handler.dispatchMessage(Handler.java:99)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.os.Looper.loop(Looper.java:137)
12-21 09:53:48.220: E/AndroidRuntime(13086): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-21 09:53:48.220: E/AndroidRuntime(13086): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 09:53:48.220: E/AndroidRuntime(13086): at java.lang.reflect.Method.invoke(Method.java:511)
12-21 09:53:48.220: E/AndroidRuntime(13086): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-21 09:53:48.220: E/AndroidRuntime(13086): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-21 09:53:48.220: E/AndroidRuntime(13086): at dalvik.system.NativeStart.main(Native Method)
是正確的方式包括圖書館依賴的共享對象?
編輯:
我注意到包名說com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity
和我也許應該注意的是,我繼承了圖書館的這項活動在我的項目,所以實際活動的軟件包名稱會有所不同。如果JNI去尋找一個名爲com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getOpenGlEsVersionNative()
的方法,而我的子類名爲com.my.package.MyActivity
,這會導致任何問題嗎?
我們需要查看正在加載的.so的logcat記錄,本機函數的C或C++聲明,以及理想情況下所安裝的.so的ndk的xx-linux-xx-objdump -T,以及期望的功能摘錄(如果確實是在文件中預設的......) –