24440

Including shared objects that library uses in Android project

Question:

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.

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.

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)

And here's the log message:

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?

Edit:

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?

Answer1:

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.

Recommend

  • Android NDK path variable for “strip” command in CMake build tool chain
  • Running apache Spark on windows
  • Where can I download a windows binary of Windres (part of Binutils)?
  • NDK build error: “fatal error: stdint.h: No such file or directory” on Mac Os X
  • Failed to create Shared Library using android-ndk in Linux?
  • Angular Material2 not all styles are applied
  • c++ using primitive types as a base class
  • Caret disappears when the background of a textbox is gray in wpf
  • Raphael.js function getBBox give back NAN/NAN/NAN in IE8
  • Javascript Array, Object, Date not defined
  • Opaque reference instead of PImpl. Is it possible?
  • Losing my session variables
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Get a trait object reference from a vector
  • Xmonad multiple submap key combos
  • c++ regex_replace not doing intended substitution
  • php script is parsing content from RTE (tt_news) but internal links are not appearing as speaking ur
  • How can I mock ui-router's resolve values when testing a state's configuration?
  • using System.Speech.Synthesis with Windows10 universal app (XAML-C#)
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • GAE: Way to get reference to an HttpSession from its ID?
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • What is the purpose of TaskExecutor in spring?
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • one Local Olampyad Questions on Informatic in 2011
  • How to use an array of arrays with array_map(…) in PHP?
  • Lost migrations and Azure database is now out of sync
  • Why is an OPTIONS request sent to the server?
  • How would I use PHP exceptions to define a redirect?
  • How to set/get protobuf's extension field in Go?
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Cassandra Data Model
  • Trying to switch camera back to front but getting exception
  • Importing jscolor library in angular 2
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Web-crawler for facebook in python
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • KeystoneJS: Relationships in Admin UI not updating
  • Net Present Value in Excel for Grouped Recurring CF