【Android】NDK的使用常见问题
2017-12-27 13:22
211 查看
Android提供了NDK工具用以编译能够Android设备上运行的C/C++程序,本质上就是交叉编译,下面给出几篇关于NDK相关的文章。
例如,我的平台是麒麟970,他是arm64的架构,Android版本是6.0(API 23),将生成的toolchain保存到
然后只需要设置好环境变量,即可开始使用交叉编译工具链:
参考:Android NDK 工具链的使用方法(Standalone Toolchain)
教程
生成设备专用的toolchain
在${NDKROOT}/build/tools下有两个脚本:make_standalone_toolchain.py 和 make-standalone-toolchain.sh,这两个脚本的功能相似,下面是脚本的使用方式(–help):
usage: make_standalone_toolchain.py [-h] --arch {arm,arm64,mips,mips64,x86,x86_64} [--api API] [--stl {gnustl,libc++,stlport}] [--unified-headers] [--force] [-v] [--package-dir PACKAGE_DIR | --install-dir INSTALL_DIR] Creates a toolchain installation for a given Android target. The output of this tool is a more typical cross-compiling toolchain. It is indended to be used with existing build systems such as autotools. optional arguments: -h, --help show this help message and exit --arch {arm,arm64,mips,mips64,x86,x86_64} --api API Target the given API version (example: "--api 24"). --stl {gnustl,libc++,stlport} C++ STL to use. --unified-headers Use unified headers. --force Remove existing installation directory if it exists. -v, --verbose Increase output verbosity. --package-dir PACKAGE_DIR Build a tarball and install it to the given directory. If neither --package-dir nor --install-dir is specified, a tarball will be created and installed to the current directory. --install-dir INSTALL_DIR Install toolchain to the given directory instead of packaging.
Usage: make-standalone-toolchain.sh [options] Generate a customized Android toolchain installation that includes a working sysroot. The result is something that can more easily be used as a standalone cross-compiler, e.g. to run configure and make scripts. Valid options (defaults are in brackets): --help Print this help. --verbose Enable verbose mode. --dryrun Unsupported. --toolchain=<name> Specify toolchain name --use-llvm No-op. Clang is always available. --stl=<name> Specify C++ STL [gnustl] --arch=<name> Specify target architecture --abis=<list> No-op. Derived from --arch or --toolchain. --ndk-dir=<path> Unsupported. --package-dir=<path> Place package file in <path> [/tmp/ndk-zonkin] --install-dir=<path> Don't create package, install files to <path> instead. --dryrun Unsupported. --platform=<name> Specify target Android platform/API level. [android-9] --force Remove existing install directory.
例如,我的平台是麒麟970,他是arm64的架构,Android版本是6.0(API 23),将生成的toolchain保存到
/tmp/ndk,那么我只需要执行如下命令
./make_standalone_toolchain.py --arch=arm64 --api=23 --install-dir=/tmp/ndk
然后只需要设置好环境变量,即可开始使用交叉编译工具链:
export PATH=/tmp/ndk/bin:$PATH export CC=aarch64-linux-android-gcc export CXX=aarch64-linux-android-g++
常见问题
error: only position independent executables (PIE) are supported.
在编译时加入下面的选项-pie -fPIE
参考:Android NDK 工具链的使用方法(Standalone Toolchain)
相关文章推荐
- 使用NDK编译含JNI的Android项目常见问题解决方案
- 解决不使用Android NDK编译的bin文件No such file or directory问题
- Android使用NDK开发项目时的一些问题
- android 使用NDK进行图像处理(openCV)时的图像转换问题(灰度图显示)
- [Android开发常见问题-12] Android开发中debug.keystore如何使用。
- [Android开发常见问题-13] 如何在CMD中直接使用adb命令
- NDK使用中常见问题
- 生成动态库so的方法|解决NDK r5b引用静态库失效的问题|在NDK的Nactive代码中使用Android Log的方法|生成Native java头文件
- android ListView组件使用常见问题或形式总结(一)
- 使用Android Studio构建Android项目常见问题收集
- Android开发使用LogCat,LogCat常见问题
- Android问题集锦转载之三:Javah 常见错误记录-NDK与JNI除错
- 【WebView】Android WebView专栏——基本使用及常见问题
- android使用磁场传感器和加速度传感器确定当前朝向(即:方位角),以及常见问题的解决办法
- 关于NDK使用的常见问题及建议和技巧(Android NDK How-To)
- Android ImageView 常见问题与使用总结
- Android上使用NDK做3D特效时碰到的一些问题及解决办法
- Android问题集锦之三十九:使用Camera录像的常见问题
- [Android开发常见问题-12] Android开发中debug.keystore如何使用。
- Android应用之——微信微博第三方sdk登录分享使用过程中的一些常见问题