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
-
Design your app, deciding which parts to implement in Java, and which parts to implement as native code.
-
Create an Android app Project in Eclipse as you would for any other Android project.
-
If you are writing a native-only app, declare the
NativeActivity
class inAndroidManifest.xml
. You can do so from the Eclipse/ADT Android Manifest Editor, or by hand-editing the file. -
Create an Android.mk file describing the native library, including name, flags, linked libraries, and source files to be compiled in the
JNI
directory. - 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
-
Place your native source under the project’s jni directory.
-
Use ndk-build to compile the native (.so, .a) libraries.
-
Build the Java component, producing the executable .dex file.
- Package everything into an APK file, containing .so, .dex, and other files needed for your app to run.