歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 編譯NDK

Android 編譯NDK

日期:2017/3/1 10:36:20   编辑:Linux編程

記錄一下自己編譯NDK的方法。目錄結構:

  1. ~/src --Android源碼目錄
  2. ~/android-ndk-r6 --google NDK目錄

1. 編譯系統

  1. a. source build/envsetup.sh
  2. b. choosecombo Device release msm8660_surf eng
  3. c. make
2. build
  1. a.src$ cd ndk/
  2. b.src$ ./build/tools/build-ndk-sysroot.sh 會得到 "ndk/build/platforms" 目錄
  3. c.src$ ./build/tools/build-platforms.sh 得到 ""src/ndk/samples" 跟 "src/ndk/platforms"目錄

3.將我們自己的 src/prebuilt/ 的 toolchain 覆蓋android-ndk-r6 裡面的相應文件
  1. a. src$ cp -af build/platforms/android-3 ../android-ndk-r6/platforms/
  2. b. src$ cp -af prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/*
  3. ../android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/
  4. c. src$ cp prebuilt/android-arm/gdbserver/gdbserver
  5. ../android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/
4 測試 hello-jni
  1. $cd android-ndk-r6/samples/hello-jni
  2. $ ./../../ndk-build
  3. Gdbserver
  4. : [arm-linux-androideabi-4.4.3]
  5. libs/armeabi/gdbserver
  6. Gdbsetup : libs/armeabi/gdb.setup
  7. Compile thumb : hello-jni <= hello-jni.c
  8. SharedLibrary : libhello-jni.so
  9. Install
  10. : libhello-jni.so => libs/armeabi/libhello-jni.so
  11. BFD:
  12. ~/android-ndk-r6/samples/hello-jni/libs/armeabi/
  13. st0hXUMa: warning: sh_link not set for section `.ARM.exidx'
  14. build成功
  15. 5. In Eclipse:
  16. a.Click File > New Android Project...
  17. b.Select the Create project from existing source radio button.
  18. c.Select any API level above Android 3.1.
  19. d.In the Location field, click Browse... and select the
  20. <ndk-root>/samples/hello-jni directory.
  21. e.Click Finish.
  22. to build
Copyright © Linux教程網 All Rights Reserved