Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNA for android

  1. I have a huge set of C source files that when compiled result in a shared library.
  2. There is also a Java version that uses JNA to access the already built c shared library. These files are available in another jar. This jar depends on jna.

First I compiled the c files and then compiled the java code. In java, there are no errors. The problem arrises only when I try to port it to android. I could easily compile the c files using the android 'ndk-build' tool. This successfully creates the shared library.

I am not able to import JNA in an Android Project because of something similar to this: Android - JNA library

However I don't understand the comments in that post. Is it possible to use JNA in Android?

I tried removing a few files from the jna.jar (the files corresponding to other architectures). Yet, I get the same error that says: The library 'jna.jar' contains native libraries that will not run on the device. Including: "com/sun/jna/android-arm/libjnidispatch.so"

The jar (the one with the java wrapper for the C library), gets imported and I can write code. But, I still get 'ExceptionInInitializerError' with the first object I create using the classes in this jar.

I am not well versed in java. I only have the knowledge of a rookie. Please bear with me and help out. Thanks.

like image 943
McMurdo Avatar asked Oct 20 '22 16:10

McMurdo


1 Answers

Maybe this is what you looking for:

  • Add Android SDK/NDK tools into PATH (used by native/Makefile).
  • Set environment variable NDK_PLATFORM (used by native/Makefile).
  • Build using: ant -Dos.prefix=android-arm dist.
  • Tests must be run on the target platform, not the build platform.
  • Add dist/jna.jar and/or dist/platform.jar to your application, as needed.
  • If you're using android-maven-plugin, jna.jar can be used as-is (native libraries will be automatically copied into your project).
  • If you're using Google's Eclipse plugin then you must manually remove libjnidispatch.so from jna.jar/lib/armeabi and add it into your project's libs/armeabi directory.
  • See http://code.google.com/p/android/issues/detail?id=17861 and http://developer.android.com/guide/practices/jni.html for more information.

Copied from https://github.com/twall/jna/blob/master/www/AndroidDevelopmentEnvironment.md:

like image 95
Chriss Avatar answered Dec 16 '22 02:12

Chriss