Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3086] Cannot use JNI for a native Android Module

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionWon't Fix
Resolution Date2012-07-17T09:07:35.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAppcelerator Modules, Titanium SDK & CLI
Labelsandroid, jni, module, ndk
ReporterFrancois Stephany
AssigneeMauro Parra-Miranda
Created2012-06-20T08:44:21.000+0000
Updated2016-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

Comments

  1. Francois Stephany 2012-07-10

    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?

JSON Source