14 September 2015

Concepts

Main Components

Android.mk

The ndk-build script looks at the file jni/Android.mk, which defines the module and its name, the source files to be compiled, build flags and libraries to link.

###Application.mk

This file enumerates and describes the modules that your app requires. This information includes:

  • ABIs used to compile for specific platforms.
  • Toolchains.
  • Standard libraries to include (static and dynamic STLport or default system).

Flow

  1. Design your app, deciding which parts to implement in Java, and which parts to implement as native code.

  2. Create an Android app Project in Eclipse as you would for any other Android project.

  3. If you are writing a native-only app, declare the NativeActivity class in AndroidManifest.xml. You can do so from the Eclipse/ADT Android Manifest Editor, or by hand-editing the file.

  4. Create an Android.mk file describing the native library, including name, flags, linked libraries, and source files to be compiled in the JNI directory.

  5. Optionally, you can create an Application.mk file configuring the target ABIs, toolchain, release/debug mode, and STL. For any of these that you do not specify, the following default values are used, respectively:
    • ABI: armeabi
    • Toolchain: GCC 4.8
    • Mode: Release
    • STL: system
  6. Place your native source under the project’s jni directory.

  7. Use ndk-build to compile the native (.so, .a) libraries.

  8. Build the Java component, producing the executable .dex file.

  9. Package everything into an APK file, containing .so, .dex, and other files needed for your app to run.


blog comments powered by Disqus