2. Extract to folder android-ndk
Linux
chmod +x android-ndk-r10c-linux-x86_64.bin
./android-ndk-r10c-linux-x86_64.bin
mv android-ndk-r10c android-ndk
3. Install CDT
Eclipse > Help > Install New Software... > Add...
http://download.eclipse.org/releases/galileo
Tick Eclipse C/C++ Development Tools (in Programming Languages) > Next, accept licences and finish
4. Create jni folder, Android.mk and your_native_code.c
jni - right click on your project > New > Folder > Folder name: jni > Finish
Android.mk - right click on jni folder > New > File > File name: Android.mk > Finish
your_native_code.c - right click on jni folder > New > File > File name: your_native_code.c > Finish
5. Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := clean.c
include $(BUILD_SHARED_LIBRARY)
6. your_native_code.c
#include <jni.h>
JNIEXPORT void JNICALL Java_cleanmemory_activity_MainActivity_cleanNow(JNIEnv* env, jobject javaThis) {
}
7. Convert to a C/C++ Project
File > New > Other... > C/C++ > Convert to a C/C++ Project (Adds C/C++ Nature) > Next > Candidates for conversion: tick YOUR PROJECT > Project type: Makefile project > Toolchains: -- Other Toolchain -- > Finish
8. Set up C/C++ Build
Right click on your project (or Alt + Enter) > Properties > C/C++ Build > uncheck Use default build command > Build command: /home/your_user_name/android-ndk/ndk-build (do not have any redundant SPACE character after "ndk-build" | having a redundant space causes Error)> Apply
Change to Behavior tab > uncheck Clean > clear the text field on the right of Build (Incremental build) > Apply > OK
9. Set up Path and Symbols
Right click on your project (or Alt + Enter) > Properties > C/C++ General > Paths and Symbols > GNU C > Add... > File system... > choose path to android-ndk/platforms/android-21/arch-arm/usr/include > OK > OK > OK
10. Load (native) library in Java Activity class for using native functions
static {
System.loadLibrary("native");
}
private native void cleanNow();
11. Calling native functions is similar to calling functions in Java
* Note: GenyMotion may not simulate the app using NDK, it causes Fatal signal 7 error. To test app, we can use Android Virtual Device (default simulator) or real device.
Reference
http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/
http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/


thankS :v
ReplyDelete