包括库的Andr​​oid项目使用共享对象 [英] Including shared objects that library uses in Android project

查看:221
本文介绍了包括库的Andr​​oid项目使用共享对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Andr​​oid项目使用具有本地code和我得到一个Android库项目的 UnsatisifiedLinkError 从本地函数库使用。

My Android project is using an Android library project that has native code and I'm getting an UnsatisifiedLinkError from a native function that library uses.

我这些共享的对象包括在我的项目的Andr​​oid.mk文件库的用途和它们正确复制到 /库 Eclipse项目目录当我建立并都在的APK / lib目录目录当我运行present。未发现该方法应在libVuforiaTracking.so

I've included in the Android.mk file of my project these shared objects the library uses and they are correctly copied over to the /libs directory of the Eclipse project when I build and are present in the apks /lib directory when I run. The method not found should be in the libVuforiaTracking.so.

下面是我的Andr​​oid.mk文件:

Here's my Android.mk file:

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)

这是正确的方式包括图书馆依赖共享对象?

Is that the correct way to include shared objects of a library dependency?

编辑:

我注意到包名称 com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity 和我也许应该注意的是,我继承了图书馆这一活动在我的项目,所以实际活动的软件包名称会有所不同。这会导致任何问题时,JNI去寻找一个名为方法<$c$c>com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getOpenGlEsVersionNative()我的子类被命名为 com.my.package.MyActivity

I noticed the package name says com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity and I should probably note that I'm subclassing this activity of the library in my project, so the package name of the actual activity would be different. Would this cause any problems when the JNI goes to look for a method named com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.getOpenGlEsVersionNative() and my subclass is named com.my.package.MyActivity?

推荐答案

的问题是,我改变了使用的本地方法 VuforiaTrackingActivity 之类的名称时,本地方法被称为 VuforiaTracking 。因此,共享对象实际上是正确加载,而这并不重要,我是延长了本地方法的名称是基于关闭的基类。我改变了方法 com.qualcomm.QCARSamples.ImageTargets.VuforiaTracking.openGlEsVersionNative com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.openGlEsVersionNative ,一切工作相应。

The issue was that I changed the name of the class that used the native method to VuforiaTrackingActivity when the native method was called VuforiaTracking. So the shared objects were in fact loaded correctly, and it didn't matter that I was extending the base class the native method names were based off of. I changed the method com.qualcomm.QCARSamples.ImageTargets.VuforiaTracking.openGlEsVersionNative to com.qualcomm.QCARSamples.ImageTargets.VuforiaTrackingActivity.openGlEsVersionNative and everything works accordingly.

这篇关于包括库的Andr​​oid项目使用共享对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆