A. HOW TO CREATE A NATIVE ANDROID PROJECT
A1. Download and install these tools:
- Eclipse (my version is Kepler SR2) from Eclipse website,
- Android SDK from Android Developers website, (and add it to the system path)
- Android NDK from Android Developers website, (and add it to the system path)
- Android ADT (Native Development Tools) from Eclipse Martketplace
- Eclipse CDT (C/C++ Development Tooling) from Eclipse Marketplace
My workspace location is ~/dev/workspace
(Please use the same workspace name, as you will need some hard path configurations in later steps)
A2. Open Eclipse. Select New->Project…->Android->Android Application Project
A3. Write these settings:
Application Name: MyApplication
Project Name: MyApplication
Package Name: com.example.myapplication
Minimum Required SDK: API 17: Android 4.2 (Jelly Bean)
Target SDK: API 17: Android 4.2 (Jelly Bean)
Compile with: API 17: Android 4.2 (Jelly Bean)
Theme: None
Click NEXT
Create Custome Launcher Icon (yes)
Create Activity (yes)
Create Project in Workspace (yes)
Click NEXT
Click NEXT again (you can change the icon later)
Create Activity (yes) - Blank Activity
Click NEXT
Activity Name: MainActivity
Layout Name: activity_main
Click FINISH
My project folder is ~/dev/workspace/MyApplication
A4. Right-click to Project Name, select Android Tools -> Add Native Support…
Set Library Name: libMyApplication.so
click FINISH
(After this step, Eclipse will create a JNI folder under your Project directory and it will create MyApplication.cpp and Android.mk files under this Project/jni folder)
A5. Clean & Build the project
A6. Add these lines somewhere in the MainActivity:
static {
System.loadLibrary("MyApplication");
}
private native String testJNI();
A7. Add this line to the end of onCreate method MainActivity:
Log.i("MainActivity", testJNI());
A8. Add these lines into Project/jni/MyApplication.cpp:
extern "C" {
JNIEXPORT jstring JNICALL Java_com_example_myapplication_MainActivity_testJNI(JNIEnv * env, jobject obj) {
return env->NewStringUTF("Hello Android Native Development");
}
};
A9. Your Android.mk can stay as automatically generated. We will not touch it for now.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyApplication
LOCAL_SRC_FILES := MyApplication.cpp
include $(BUILD_SHARED_LIBRARY)
A10. Connect your device to the computer and click Run. Check the logcat for the “Hello Android Native Development”
Note 1: You can setup a Logcat filter to see only the log lines of your app
Note 2: Check Android Developers to see how to connect a hardware device
THUS YOU ARE ABLE TO COMPILE AND RUN A NATIVE ANDROID PROJECT. I DIDN’T TOUCH THE TEXT “HELLO WORLD” ON THE SCREEN BECAUSE WE WILL CHANGE THIS LATER WHEN ADDING OF.
AFTER HERE I WILL TRY TO EXPLAIN HOW TO ADD OPENFRAMEWORKS TO THIS NATIVE ANDROID PROJECT AS A SHARED LIBRARY.