我的 Android 项目正在使用具有本机代码的 Android 库项目,并且我正在UnsatisifiedLinkError
从库使用的本机函数中获取一个。
我已经在我的项目的 Android.mk 文件中包含了库使用的这些共享对象,它们在我构建时被正确复制到 Eclipse 项目的目录中,并且在我运行时/libs
出现在 apks目录中。/lib
找不到的方法应该在 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
吗?