当前位置: 首页 > 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/

http://www.lryc.cn/news/368261.html

相关文章:

  • SpringBoot的学习要点
  • vue3引入cesium和olcs
  • 代码随想录算法训练营第25天|回溯
  • Ajax 快速入门
  • 面试官:前端实现图片懒加载怎么做?这不是撞我怀里了嘛!
  • 每天学习一个Windows命令或Linux命令——seq
  • C++设计模式-中介者模式,游戏对象之间的碰撞检测
  • Rust-02-变量与可变性
  • mov指令中不允许的操作——汇编语言
  • Python进阶-部署Flask项目(以TensorFlow图像识别项目WSGI方式启动为例)
  • WooYun-2016-199433 -phpmyadmin-反序列化RCE-getshell
  • 社交“学习伙伴”:Meta Llama助力对话升级
  • LabVIEW 反向工程的实现与法律地位
  • Python怎么做单元测试
  • ghidra
  • 如何解决网络问题?
  • 高速USB转串口芯片CH343
  • C++ MPI多进程并发
  • UFS协议入门-分层结构
  • Docker Desktop - WSL distro terminated abruptly
  • HTML-CSS练习例子
  • 【JavaScript脚本宇宙】创造声音的魔法:深入了解Web音频处理库
  • 苹果需要专注于让人工智能变得实用,而不是华而不实
  • 安全专业的硬件远控方案 设备无网也能远程运维
  • Freeswitch-soundtouch-变声开发
  • Unity2D游戏制作入门 | 09(之人物动画制作)
  • 【自动部署】4.阿里云ECS服务器 IDEA自动部署项目
  • [Algorithm][动态规划][01背包问题][目标和][最后一块石头的重量Ⅱ]详细讲解
  • LabVIEW控制PLC的实现方式
  • JSTL知识点讲解与配置