2009년 12월 23일 수요일

NDK 예제 및 활용

  1. NDK 디렉토리
    • C:\apps\Brew_tools\apps\cygwin\home\Administrator\android-ndk-1.5_r1\apps\hello-jni\project\src\com\example\hellojni\
      • APP(JAVA) 소스가 있음
    • C:\apps\Brew_tools\apps\cygwin\home\Administrator\android-ndk-1.5_r1\sources\samples\hello-jni\
      • Native(C) 소스가 있음
    • C:\apps\Brew_tools\apps\cygwin\home\Administrator\android-ndk-1.5_r1\out\apps\hello-jni\android-1.5-arm\
      • Build 후 생성되는 so(Shared Object)를 갖고 있음



  2. Build 하기

    • NDK 홈으로 이동
      • cd ~/android-ndk-1.5_r1
    • Build
      • make APP=hello-jni

  3. NDK 활용

    1. Native Code 만들기(hello-jni 에서 복사)
      • mkdir ~/android-ndk-1.5_r1/sources/samples/hi-jni/

      • cp -r ~/android-ndk-1.5_r1/sources/samples/hello-jni/* ~/android-ndk-1.5_r1/sources/samples/hi-jni/

      • mv ~/android-ndk-1.5_r1/sources/samples/hi-jni/hello-jni.c ~/android-ndk-1.5_r1/sources/samples/hi-jni/hi-jni.c

    2. Nitive Code Mk 파일 수정

      •  vi ~/android-ndk-1.5_r1/sources/samples/hi-jni/Android.mk
        • LOCAL_MODULE := hello-jni hi-jni
        • LOCAL_SRC_FILES := hello-jni.c hi-jni.c


    3. Native Code 수정
      • vi ~/android-ndk-1.5_r1/sources/samples/hi-jni/hi-jni.c
        • jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
        • jstring Java_com_example_hijni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
        • java 패키지명과 동일하게 설정.
    4. APP 만들기(hi-jni 에서 복사)
      • mkdir ~/android-ndk-1.5_r1/apps/hi-jni
      • cp -r ~/android-ndk-1.5_r1/apps/hello-jni/* ~/android-ndk-1.5_r1/apps/hi-jni/
    5. APP Mk 파일 수정(모듈명 변경)
      • vi ~/android-ndk-1.5_r1/apps/hi-jni/Application.mk
        • APP_MODULES := hello-jni hi-jni
    6. Build
      • cd ~/android-ndk-1.5_r1Build
      • make APP=hi-jni

댓글 없음:

댓글 쓰기