当前位置: 首页 > news >正文

在 Linux 系统上安装 Android NDK

在 Linux 系统上安装 Android NDK

  • 1. Android NDK
  • 2. NDK Downloads
    • 2.1. Latest LTS Version (r26d)
    • 2.2. Old Unsupported Versions
  • 3. 安装 NDK
  • 4. Get started with the NDK (NDK 使用入门)
  • References

1. Android NDK

https://developer.android.com/ndk

The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages.
Android NDK 是一个工具集,可让您以原生代码 (using languages such as C and C++) 实现应用的各个部分。对于特定类型的应用,这可以帮助您重复使用以这些语言编写的代码库。

The Android Native Development Kit (NDK) provides a cross-compiling tool for compiling code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) for Android. The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in 2018.

The NDK includes support for CMake and its own ndk-build (based on GNU Make). For CPU profiling, the NDK also includes simpleperf which is similar to the Linux perf tool, but with better support for Android and specifically for mixed Java/C++ stacks.

2. NDK Downloads

https://developer.android.com/ndk/downloads

https://github.com/android/ndk/wiki

Select the NDK package for your development platform. In most cases it will be easier to use the Android SDK manager to install the NDK.

2.1. Latest LTS Version (r26d)

android {ndkVersion "26.3.11579264"
}
PlatformPackageSize (Bytes)SHA1 Checksum
Windows 64-bitandroid-ndk-r26d-windows.zip665022840c7ea35ffe916082876611da1a6d5618d15430c29
Macandroid-ndk-r26d-darwin.dmg1655224062703100c3d721b04e09f02f3fddc5f1f5ced28b10
Linux 64-bit (x86)android-ndk-r26d-linux.zip668556491fcdad75a765a46a9cf6560353f480db251d14765
https://dl.google.com/android/repository/android-ndk-r26d-linux.zip

2.2. Old Unsupported Versions

https://github.com/android/ndk/wiki/Unsupported-Downloads

Note: these obsolete versions of the NDK are no longer supported.

r25c

https://dl.google.com/android/repository/android-ndk-r25c-linux.zip

r24

https://dl.google.com/android/repository/android-ndk-r24-linux.zip

r23c

https://dl.google.com/android/repository/android-ndk-r23c-linux.zip

r22b

https://dl.google.com/android/repository/android-ndk-r22b-linux-x86_64.zip

r21e

3. 安装 NDK

https://dl.google.com/android/repository/android-ndk-r21e-linux-x86_64.zip
  1. 下载并解压 android-ndk-r26d-linux.zip

wget https://dl.google.com/android/repository/android-ndk-r26d-linux.zip --no-check-certificate

(base) yongqiang@yongqiang:~/software$ wget https://dl.google.com/android/repository/android-ndk-r26d-linux.zip
(base) yongqiang@yongqiang:~/software$ chmod a+x android-ndk-r26d-linux.zip
(base) yongqiang@yongqiang:~/software$ unzip android-ndk-r26d-linux.zip
(base) yongqiang@yongqiang:~/software$ rm -rf android-ndk-r26d-linux.zip
(base) yongqiang@yongqiang:~/software$ cd android-ndk-r26d/
(base) yongqiang@yongqiang:~/software/android-ndk-r26d$ pwd
/home/yongqiang/software/android-ndk-r26d
(base) yongqiang@yongqiang:~/software/android-ndk-r26d$
  1. 为当前用户永久配置环境变量

~/.bashrc

(base) yongqiang@yongqiang:~$ vim ~/.bashrc
...
export NDKROOT=/home/yongqiang/software/android-ndk-r26d
export PATH=${NDKROOT}:${PATH}
...
(base) yongqiang@yongqiang:~$ source ~/.bashrc
  1. 为所有用户永久配置环境变量

/etc/profile

(base) yongqiang@yongqiang:~$ vim /etc/profile
...
export NDKROOT=/home/yongqiang/software/android-ndk-r26d
export PATH=${NDKROOT}:${PATH}
...
(base) yongqiang@yongqiang:~$ source /etc/profile
  1. 验证 NDK 安装

ndk-build -v

(base) yongqiang@yongqiang:~$ ndk-build -v
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
(base) yongqiang@yongqiang:~$
(base) yongqiang@yongqiang:~$ echo ${PATH}
/home/yongqiang/software/android-ndk-r26d:/home/yongqiang/vulkan/1.3.239.0/x86_64/bin:/home/yongqiang/miniconda3/bin:/home/yongqiang/miniconda3/condabin:/home/yongqiang/vulkan/1.3.239.0/x86_64/bin:
...

4. Get started with the NDK (NDK 使用入门)

https://developer.android.com/ndk/guides

The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input. The NDK may not be appropriate for most novice Android programmers who need to use only Java code and framework APIs to develop their apps.
Native Development Kit (NDK) 是一套工具,使你能够在 Android 应用中使用 C 和 C++ 代码,并提供众多平台库,你可使用这些平台库管理原生 activity 和访问实体设备组件,例如传感器和触控输入。NDK 可能不适合大多数 Android 编程初学者,这些初学者只需使用 Java 代码和框架 API 开发应用。

However, the NDK can be useful for cases in which you need to do one or more of the following:

  • Squeeze extra performance out of a device to achieve low latency or run computationally intensive applications, such as games or physics simulations.
    进一步提升设备性能,以降低延迟或运行游戏或物理模拟等计算密集型应用。
  • Reuse your own or other developers’ C or C++ libraries.
    重复使用你自己或其他开发者的 C 或 C++ 库。

Using Android Studio 2.2 and higher, you can use the NDK to compile C and C++ code into a native library and package it into your APK using Gradle, the IDE’s integrated build system. Your Java code can then call functions in your native library through the Java Native Interface (JNI) framework.
你可以在 Android Studio 2.2 或更高版本中使用 NDK 将 C 和 C++ 代码编译到原生库中,然后使用 Android Studio 的集成构建系统 Gradle 将原生库打包到 APK 中。Java 代码随后可以通过 Java 原生接口 (JNI) 框架调用原生库中的函数。

Android Studio’s default build tool to compile native libraries is CMake. Android Studio also supports ndk-build due to the large number of existing projects that use the build toolkit. However, if you are creating a new native library, you should use CMake.
Android Studio 编译原生库的默认构建工具是 CMake。由于很多现有项目都使用 ndk-build 构建工具包,因此 Android Studio 也支持 ndk-build。不过,如果您要创建新的原生库,则应使用 CMake。

The Android Native Development Kit (NDK): a set of tools that allows you to use C and C++ code with Android.
这套工具使您能在 Android 应用中使用 C 和 C++ 代码。

CMake: an external build tool that works alongside Gradle to build your native library. You do not need this component if you only plan to use ndk-build.
如果你只计划使用 ndk-build,则不需要此组件。

LLDB: the debugger Android Studio uses to debug native code.
Android Studio 用于调试原生代码的调试程序。

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

相关文章:

  • 呼叫中心系统的国产化替代方案
  • 【Flutter】 TextField限制长度时, 第三方手写输入法、ios原始拼音输入法输入被吞问题
  • swift微调牧歌数据电商多模态大语言模型
  • 【Spring6】1-12章源码级深入详解 IoC
  • 网络安全(补充)
  • 外卖抢单神器
  • 重学java 66.IO流 转换流
  • Linux-笔记 设备树插件
  • 3072. 将元素分配到两个数组中 II Rust 线段树 + 离散化
  • GIGE 协议摘录 —— GVSP 协议(三)
  • Web前端ES6-ES13笔记合集(下)
  • 【ARFoundation自学05】人脸追踪(AR Face manager)实现
  • 力扣1146.快照数组
  • Stable Diffusion详解
  • 添加L1/L2损失函数,以及AttributeError: ‘NoneType‘ object has no attribute ‘data‘
  • 230. Kth Smallest Element in a BST
  • 5分钟即可掌握的前端高效利器:JavaScript 策略模式
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • GDB 调试 Mysql 实战(三)优先队列排序算法中的行记录长度统计是怎么来的(上)...
  • Java的Interrupt与线程中断
  • Java多态
  • JS专题之继承
  • Just for fun——迅速写完快速排序
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • Redis提升并发能力 | 从0开始构建SpringCloud微服务(2)
  • SpringBoot 实战 (三) | 配置文件详解
  • tab.js分享及浏览器兼容性问题汇总
  • WordPress 获取当前文章下的所有附件/获取指定ID文章的附件(图片、文件、视频)...
  • 持续集成与持续部署宝典Part 2:创建持续集成流水线
  • 欢迎参加第二届中国游戏开发者大会
  • 批量截取pdf文件
  • 用jquery写贪吃蛇
  • 智能网联汽车信息安全
  • 06-01 点餐小程序前台界面搭建
  • 从如何停掉 Promise 链说起
  • ​​​​​​​​​​​​​​Γ函数
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (分享)自己整理的一些简单awk实用语句
  • (附源码)node.js知识分享网站 毕业设计 202038
  • (附源码)springboot家庭装修管理系统 毕业设计 613205
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (附源码)计算机毕业设计SSM保险客户管理系统
  • (六)vue-router+UI组件库
  • (三)Hyperledger Fabric 1.1安装部署-chaincode测试
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • (四) 虚拟摄像头vivi体验
  • (转)Linux下编译安装log4cxx
  • (转)Linux整合apache和tomcat构建Web服务器
  • (转)创业的注意事项
  • ***汇编语言 实验16 编写包含多个功能子程序的中断例程
  • ./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’: ./incl
  • .gitignore
  • .net core使用EPPlus设置Excel的页眉和页脚
  • .Net接口调试与案例
  • .Net下的签名与混淆