Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a solution for doing the things the other way around: building both the external library and the Android package from standard Makefiles.</p> <p>As a prerequisite, you need to install everything needed to do command line Android development:</p> <ul> <li>A standalone toolchain, see the documentation included in the Android NDK;</li> <li>ant.</li> </ul> <p>The structure of the example is: a directory for the external library and a directory for the Android sources at the same level with a Makefile in each directory and a top-level, recursive Makefile:</p> <pre><code>Makefile mylib/ Makefile android/ Makefile </code></pre> <p>The <code>mylib/Makefile</code> builds a static library:</p> <pre><code>AR=/path/to/standalone/bin/arm-linux-androideabi-ar CC=/path/to/standalone/bin/arm-linux-androideabi-gcc libmylib.a: mylib.o $(AR) rcs libmylib.a mylib.o mylib.o: mylib.c $(CC) -c mylib.c -o mylib.o </code></pre> <p>The <code>android/Makefile</code> is providing rules to build the Android package:</p> <ul> <li>we need a dependency to copy <code>mylib</code> when it's modified;</li> <li>we're using a <code>jni/ndkmake.c</code> file to wrap the calls to <code>mylib</code> and provide android specific stuff;</li> <li>the android package depends on the Java sources and on the shared library.</li> </ul> <p>The Makefile provides two target: <code>release</code> (the default) and <code>debug</code> to build either a release package or a debug one.</p> <pre><code>NDK_BUILD=/path/to/ndk-build JAVASRC=src/com/example/ndkmake/NdkMake.java release: bin/NdkMake-release-unsigned.apk debug: bin/NdkMake-debug.apk bin/NdkMake-release-unsigned.apk: libs/armeabi/libndkmake.so $(JAVASRC) ant release bin/NdkMake-debug.apk: libs/armeabi/libndkmake.so $(JAVASRC) ant debug libs/armeabi/libndkmake.so: jni/ndkmake.c jni/libmylib.a $(NDK_BUILD) jni/libmylib.a: ../mylib/libmylib.a cp ../mylib/libmylib.a jni/libmylib.a </code></pre> <p>The <code>Android.mk</code> file provides rules to include the static library in the build, as a prebuilt. We're including headers from the <code>mylib</code> library using <code>LOCAL_EXPORT_C_INCLUDES</code>.</p> <pre><code>LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := ndkmake LOCAL_SRC_FILES := ndkmake.c LOCAL_STATIC_LIBRARIES := mylib-prebuilt include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := mylib-prebuilt LOCAL_SRC_FILES := libmylib.a LOCAL_EXPORT_C_INCLUDES := ../mylib/ include $(PREBUILT_STATIC_LIBRARY) </code></pre> <p>Now we only need a top-level Makefile to build the two subdirectories:</p> <pre><code>all: libmylib package libmylib: cd mylib &amp;&amp; $(MAKE) package: cd android &amp;&amp; $(MAKE) </code></pre> <p>Any change to the library, to the jni sources or to the Java sources will trigger a rebuild of the package.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload