I write the steps to create a purely native app project on Eclipse + ADT (23.0.4 version) with Android NDK installed(revision 10d):
1. Before starting, ensure that the Eclipse IDE is aware of the location of the NDK. This configuration is hide in Window > Preferences > Android > NDK. If you want to build it from the command line at some point, update your PATH environment variable with the location of the directory that contains the NDK. For example, in bash:
2. Create the project as usual.
3. Delete all of the default-created activities and layouts; in a purely native app these aren't necessary.
4. Right-click the project icon and go to Android Tools. Select Add Native Support.... The name in the text field will be the native code library which will be generated by the build process, in this case: nativedemo
5. A purely native project requires a special Manifest setup inside the application tag, like this:
I comment the specific configurations for this case:
- application attribute android:hasCode="false": When the value is "false", the system does not try to load any application code when launching components.
- The activity name to android.app.NativeActivity: NativeActivity is a helper class in order to write a completely native activity. It's a hidden but common class that handles the communication between the Android framework and the native code.
- The android:value attribute of the meta-data tag specifies the name of the shared library containing the entry point to the application:
4. Build file setup. The previous Add Native Support menu operation has generated the Android build file (Android.mk), but we want to add some configuration lines in order to use key external libraries (More about NDK build system and native libraries):
// Android’s existing libraries linked in dynamically LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 // static NDK library to enable us to write a pure native app LOCAL_STATIC_LIBRARIES := android_native_app_glue // This tells the build system to import the static library into the app. $(call import-module, android/native_app_glue)
The final Android.mk file will look like this:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := nativedemo LOCAL_SRC_FILES := NativeDemo.cpp LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2 LOCAL_STATIC_LIBRARIES := android_native_app_glue include $(BUILD_SHARED_LIBRARY) $(call import-module,android/native_app_glue)
This article can be useful too: Using Eclipse for Android C/C++ Development | Android blog