我的Android项目正在使用具有本机代码的Android库项目,而我从库使用的本机函数中获取UnsatisifiedLinkError
。
我已经在项目的Android.mk文件中包含了这些库使用的共享对象,并且在构建时它们被正确地复制到Eclipse项目的/libs
目录并且存在于apks中{我运行时的{1}}目录。未找到的方法应该在libVuforiaTracking.so。
这是我的Android.mk文件:
/lib
这是日志消息:
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)
,我应该注意到我在项目中继承了这个库的活动,所以实际活动的包名称会有所不同。当JNI寻找名为com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity
的方法并且我的子类名为com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getOpenGlEsVersionNative()
时会导致任何问题吗?
答案 0 :(得分:0)
问题是,当调用本机方法VuforiaTrackingActivity
时,我将使用本机方法的类的名称更改为VuforiaTracking
。所以共享对象实际上是正确加载的,并且我扩展了本机方法名称所基于的基类并不重要。我将方法com.qualcomm.QCARSamples.ImageTargets.VuforiaTracking.openGlEsVersionNative
更改为com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.openGlEsVersionNative
,一切都正常。