Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8505] Android: Module build.xml no longer compiles C++ source code in the "jni" directory

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-04-26T10:22:52.000+0000
Affected Version/sRelease 1.8.2
Fix Version/sRelease 2.1.0, Sprint 2012-08
ComponentsAndroid
Labelscore, module_module, pe-planning-2012-08, qe-port, regression
ReporterPaul Mietz Egli
AssigneeStephen Tramer
Created2012-03-16T10:22:16.000+0000
Updated2012-06-20T12:29:51.000+0000

Description

Marshall's post on using native libraries in an Android module (http://developer.appcelerator.com/blog/2011/01/titanium-and-the-android-ndk.html) states that you need to place C++ source files in the jni directory of the module project and they will be compiled into .so files and included in the module. This is not the case in version 1.8.2 of the SDK -- the build.xml file under TITANIUM_HOME/mobilesdk/osx/1.8.2/modules/android never looks in that directory. To get the described behavior, the following targets can be added to the module's build.xml file:
<property name="genlocaljni" location="${build}/generated/local-jni"/>
<target name="build.jni">
    <mkdir dir="${genlocaljni}"/>
    <copy todir="${genlocaljni}">
        <fileset dir="${ti.module.root}">
            <include name="jni/**"/>
        </fileset>
    </copy>
    <check.ndk/>
    <condition property="ndk.build" value="${ndk.path}/ndk-build.cmd" else="${ndk.path}/ndk-build">
        <os family="windows"/>
    </condition>
    <exec executable="${ndk.build}" dir="${genlocaljni}" failonerror="true">
        <arg value="TI_MOBILE_SDK=${mobilesdk.dir}"/>
        <arg value="NDK_PROJECT_PATH=${genlocaljni}"/>
        <arg value="PYTHON=${python.exec}"/>
        <arg value="V=${ndk.verbose}"/>
    </exec>
    <copy todir="${libs}">
        <fileset dir="${genlocaljni}/libs">
            <include name="**/*.so"/>
        </fileset>
    </copy>
</target>
 
<target name="post.compile">
    <antcall target="build.jni"/>
</target>
Ideally, these targets would be part of the SDK's build.xml. In the meantime, it would be good to update the blog post to indicate that it is out of date.

Attachments

FileDateSize
jni_module.tar.gz2012-04-18T20:22:31.000+00004858

Comments

  1. Marshall Culpepper 2012-04-03

    Note: We should move (and update if necessary) the old blog post content over to Wiki so it is easier to find for people who want to use C++ modules
  2. Stephen Tramer 2012-04-18

    The following should be reviewed as part of resolving this ticket: [Step 2: Understanding the Different Parts of a Module : "jni"](https://wiki.appcelerator.org/display/guides2/Android+Module+Development+Guide#AndroidModuleDevelopmentGuide-Step2%3AUnderstandingtheDifferentPartsofaModule)
  3. Stephen Tramer 2012-04-18

    Testing

    ----

    Download the attached jni_module.tar.gz

    Build the module from source (org.appcelerator.jnitest)

    Create a new Titanium application for Android (either command line or studio) with the following app.js:

       var native = require('org.appcelerator.jnitest');
       alert(native.hello());
       

    Add v0.1 of 'org.appcelerator.jnitest' as a module dependency for the application, and copy the dist built from step 2. above either into the project or the Titanium install directory.

    Run the application on an Android device or emulator

    *SUCCESS*: You see an alert with the contents "Hello from JNI!" *FAIL*: Any other result
  4. Michael Pettiford 2012-06-20

    Closing issue Tested with Ti Studio build 2.1.0.201206200844 Ti Mobile SDK 2.1.0.v20120619172256 hash rd3a84b13 OSX Lion 10.7.3 Nexus S OS 4.0.4 The expected behavior is shown

JSON Source