Android NDK Example


- source project :

1. make a new 'NdkExample' project under the 'ndk-root/apps' folder.

2. make a JNI java file(class) for wrapping.

public class NdkExample {
    static {

    public native String stringFromJni();

3. make a '' file under the 'ndk-root/apps/NdkExample' folder.

APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES := NdkExample

4. make a 'NdkExample/project' and make 'jni' and 'libs' folder under the 'project' folder.

5. make a '' file under the 'jni' folder.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := NdkExample
LOCAL_SRC_FILES := NdkExample.c

6. move to 'NdkExample/bin' folder and make a header file from the 'NdkExample.class' file

javah com.example.NdkExample

7. move the header file to 'NdkExample/project/jni' folder and rename to 'NdkExample.h' for using easier.

8. make a 'NdkExample.c' file under the 'NdkExample/project/jni' folder.

#include "NdkExample.h"
#include <string.h>

jstring Java_com_example_NdkExample_stringFromJni(JNIEnv *env, jobject thiz)
    return (*env)->NewStringUTF(env, "Hello world from native code.");

9. compile the project under the 'ndk-root' folder.

make APP=NdkExample

10. move the '' file to 'NdkExample/libs/armeabi' folder.
when you don't have the 'NdkExample/libs/armeabi' folder, you should make it.

*NOTE: You must change the name of loadLibrary like below.
the name is used by '' file without 'lib' prefix and '.so' surfix.


11. use the library on your Android SDK project that you made(ex, 'NdkExample')

public class NdkExampleMain extends Activity {
    /** Called when the activity is first created. */
    NdkExample m_jniProject;
    public void onCreate(Bundle savedInstanceState) {
       m_jniProject = new NdkExample();
        TextView tv = (TextView)findViewById(;

12. then, you can see the "Hello world from native code." text on your AVD emulator.

13. finish.

Posted by 바츠05 트랙백 0 : 댓글 0

윈도우에서 계정에 한글이 포함되어 있으면,
AVD가 실행이 되지 않는다.

이럴때는, 영문계정을 만들어서 해도 되겠지만,
간단하게 AVD의 경로를 수정해도 된다.

android move avd -n AVD8 -p c:\avd\AVD8

Posted by 바츠05 트랙백 0 : 댓글 0