Install NDK in Eclipse/Android Studio

Install NDK in Eclipse/Android Studio

  1、 Download NDK

https://developer.android.com/tools/sdk/ndk/index.html

  2、Install NDK

$ tar xvf android-ndk-r8e-linux-x86_64.tar.bz2 -C ~/Software/Android/
$ cd Android
$ mv android-ndk-r8e/ ndk/

  3、add PATH

复制代码
$ vim ~/.bashrc
//----------------- add the following text ----------------------
export NDK_HOME=/home/linx/Software/Android/ndk
export PATH=${NDK_HOME}:$PATH
//------------------------------------------------------------------------
$ source ~/.bashrc
复制代码

  4、test the ndk

复制代码
$ pwd
~/Software/Android/ndk/samples/hello-gl2

$ ndk-build
Compile++ thumb  : gl2jni <= gl_code.cpp
StaticLibrary  : libstdc++.a
SharedLibrary  : libgl2jni.so
Install        : libgl2jni.so => libs/armeabi/libgl2jni.so    
复制代码

  the object file is "libs/armeabi/libgl2jni.so"

  the ndk install success.

  then add the ndk to IDE.

 

  Eclipse :

  1、download CDT

  1) offline

http://www.eclipse.org/cdt/downloads.php

  2) online

Help -> Install New Software

  add the URL

http://download.eclipse.org/tools/cdt/releases/juno/

  then the CDT install automatic.

  2、run ndk-build in the project exist

$ pwd
~/Software/Android/ndk/samples/hello-jni

$ ndk-build

  3、Import the project first

File -> New -> Project.. -> Android Project from Existing Code

  browse form the project root directory.

  4、config the NDK in IDE

  1) File -> Properties

  2) builders -> New -> Program -> OK

  3)in Edit Configuration

Name : hellojni (the project you want to build)

  Table Main :

Location :
/bin/bash
Working Directory :
/bin
Arguments :
-c "cd ~/Software/Android/ndk/samples/hello-jni/ && ndk-build"

  Table Refresh :

click on "Refresh resources upon completion."

then choose the "Specific resources"

finally choose the "libs" in "Specific resources" and Finish it 

  Table Build Options :

click on everything in "Run in builder"

then choose the "Specify Resources"

finally choose the "jni"  in "Specify Resources"

  Finish.

这些都是 Android NDK 内部的 `Android.mk` 文件。其中,`./android-ndk-r25c/sources/android/native_app_glue/Android.mk` 是用于编译 Native Activity 示例应用程序的 `Android.mk` 文件;`./android-ndk-r25c/sources/android/support/Android.mk` 是包含一些 Android 支持库的 `Android.mk` 文件;`./android-ndk-r25c/sources/android/ndk_helper/Android.mk` 是包含一些辅助函数和类的 `Android.mk` 文件;`./android-ndk-r25c/sources/android/cpufeatures/Android.mk` 是用于编译 `cpufeatures` 库的 `Android.mk` 文件,该库提供了一些 CPU 相关的信息和功能;`./android-ndk-r25c/sources/cxx-stl/llvm-libc++abi/Android.mk` 和 `./android-ndk-r25c/sources/cxx-stl/llvm-libc++/Android.mk` 是用于编译 C++ STL 库的 `Android.mk` 文件,分别对应 libc++abi 和 libc++ 两个 STL 库;`./android-ndk-r25c/sources/third_party/googletest/Android.mk` 是用于编译 Google Test 测试框架的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/shaderc/Android.mk` 是用于编译 Shaderc 编译器的 `Android.mk` 文件,该编译器可以将 GLSL 代码编译成 SPIR-V 代码;`./android-ndk-r25c/sources/third_party/shaderc/libshaderc/Android.mk` 是用于编译 Shaderc 库的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/shaderc/libshaderc_util/Android.mk` 是用于编译 Shaderc Util 库的 `Android.mk` 文件,该库提供了一些辅助函数和类;`./android-ndk-r25c/sources/third_party/shaderc/third_party/Android.mk` 是用于编译 Shaderc 编译器依赖的第三方库的 `Android.mk` 文件,包括 glslang 和 spirv-tools 两个库;`./android-ndk-r25c/sources/third_party/shaderc/third_party/glslang/Android.mk` 是用于编译 glslang 库的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/shaderc/third_party/spirv-tools/Android.mk` 是用于编译 spirv-tools 库的 `Android.mk` 文件;`./android-ndk-r25c/sources/third_party/vulkan/src/build-android/jni/Android.mk` 是用于编译 Vulkan 库的 `Android.mk` 文件。 如果您要在 Android NDK 中编写自己的 `Android.mk` 文件,可以参考这些示例文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值