[AC-3086] Cannot use JNI for a native Android Module
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2012-07-17T09:07:35.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Appcelerator Modules, Titanium SDK & CLI |
Labels | android, jni, module, ndk |
Reporter | Francois Stephany |
Assignee | Mauro Parra-Miranda |
Created | 2012-06-20T08:44:21.000+0000 |
Updated | 2016-03-08T07:48:08.000+0000 |
Description
How to reproduce:
- Create a Titanium Module Project in Titanium Studio:
* project name: headphones
* module id: be.tulipemoutarde.headphones
* deployment target: 'Android' / SDK: 2.0.2GA
- Edit the build.properties file to match your setup.
- Create a JNI folder and create an Android.mk, a headphones.c file.
- Edit the HeadphonesModule.java to load the native library and create a method that will call a C function.
- Edit the app.js to call the java method.
- plug an android phone (or if you are brave enough, launch an emulator)
- Get a logcat (e.g., with DDMS)
- run the app on your phone with 'ant install'
You will see "java.lang.unsatisfiedLinkError: Couldn't load headphones: findLibrary returned null"
and "Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lbe/tulipemoutarde/headphones/HeadphonesModule;"
I don't have any errors in the output when it compiles. I guess there's a problem somewhere in the build process (does the libheadphones.so copied in the right directory?), but my knowledge of Ant and the java tools is too limited :/
You can have a look/clone the project. Don't forget to adapt the paths in build.properties ;)
https://github.com/fstephany/Titanium-JNI-demo
I've managed to make it work. The process is a bit long but I guess it could be automated in the build.xml? Here's how to proceed: * ant clean * ndk-build * create the directory libs/armeabi-v7a and copy libs/armeabi/libheadphones.so into it. * ant dist * titanium install The step where I copy the libheadpones.so in the armeabi-v7a is a bit weird but it works with my Samsung Galaxy S2. Is there an easiest way to make this work or should I write a script to perform all those operations?