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

android-ndk开发(2): macOS 安装 ndk

android-ndk开发(2): macOS 安装 ndk

2025/05/05

1. 概要

对于 android-ndk 在 r23 之前的版本,官方提供了 .zip 文件, 解压即安装。

对于 android-ndk 在 r23 以及之后的版本, 官方只提供了 .dmg 文件, 不能简单的解压完成安装。

2. ndk >= r23, macOS 怎么安装 ?

android ndk 从 r23 开始, 不再提供 macOS 平台的 .zip 安装包(如android-ndk-r22b-darwin-x86_64.zip), 只提供 .dmg 格式的安装包。链接 [1] 可以确认。这导致无法像 Windows 和 Linux 一样, 解压 .zip 就完成 ndk 的安装。

以 android-ndk-r27c-darwin.dmg 为例, 双击后显示两个文件: AndroidNDK12479018.app 和 source.properties。 双击 AndroidNDK12479018.app 后感觉完成了安装, 但在 /Application, /Library, ~/Application, ~/Library 4个目录找不到安装的内容。

手动解压 AndroidNDK12479018.app,里面的 NDK 目录是工具链, CodeSign 这玩意儿暂时不知道用处,感觉就是故意使绊子。

为了一劳永逸解决 macOS 上 ndk >= r23 版本的安装, 上述过程写为 Python 脚本。基本思路是:挂载 .dmg -> 找到 .app 文件 -> 找 NDK 目录 -> 拷贝到目标目录。

import subprocess
import shutil
import os
import timedef mount_and_copy(dmg_path, target_dir):target_dir = os.path.expanduser(target_dir)try:print(f"⏳ 正在挂载 {dmg_path}...")mount_result = subprocess.run(["hdiutil", "attach", "-nobrowse", dmg_path],capture_output=True,text=True,check=True)# 解析挂载路径mount_path = Nonefor line in mount_result.stdout.splitlines():if "/Volumes" in line:mount_path = line.split("\t")[-1].strip()breakif not mount_path:raise FileNotFoundError("无法定位挂载点")time.sleep(2)  # 等待文件系统稳定# 动态查找AndroidNDK*.appapp_files = [f for f in os.listdir(mount_path)if f.startswith("AndroidNDK") and f.endswith(".app")]# e.g. AndroidNDK12479018.app for android-ndk-r27cif not app_files:available = "\n".join(os.listdir(mount_path))raise FileNotFoundError(f"未找到AndroidNDK*.app文件,当前卷内容:\n{available}")app_path = os.path.join(mount_path, app_files[0])print(f"  定位到应用包:{app_path}")# 验证NDK路径ndk_source = os.path.join(app_path, "Contents", "NDK")if not os.path.exists(ndk_source):raise FileNotFoundError(f"NDK目录不存在:{ndk_source}")# 准备目标目录os.makedirs(target_dir, exist_ok=True)print(f"  目标目录:{target_dir}")# 执行复制(保留元数据)print("⚙️ 开始复制NDK文件...")shutil.copytree(ndk_source,target_dir,dirs_exist_ok=True,copy_function=shutil.copy2)# 卸载镜像print("⏳ 正在卸载...")subprocess.run(["hdiutil", "detach", mount_path], check=True)print(f"  安装完成!路径:{target_dir}")except subprocess.CalledProcessError as e:print(f"❌ 命令执行失败:{e.stderr}")if 'mount_path' in locals() and os.path.exists(mount_path):print(f"⚠️ 尝试手动卸载:hdiutil detach {mount_path}")except Exception as e:print(f"❌ 错误:{str(e)}")if __name__ == "__main__":dmg_path = os.path.join(os.getcwd(), "android-ndk-r27c-darwin.dmg")mount_and_copy(dmg_path, "/Users/zz/soft/toolchains/android-ndk-r27c")

References

  • https://github.com/android/ndk/wiki/Unsupported-Downloads
http://www.xdnf.cn/news/285823.html

相关文章:

  • PyTorch_自动微分模块
  • 时间同步服务核心知识笔记:原理、配置与故障排除
  • 因为gromacs必须安装cuda(系统自带的NVIDIA驱动不行),这里介绍下如何安装cuda
  • 学习路线(机器人软件架构)
  • Java常用注解大全(基于JDK17+SpringBoot3)
  • 对ubuntu的简单介绍
  • Redis:现代服务端开发的缓存基石与电商实践-优雅草卓伊凡
  • 题目 3321: 蓝桥杯2025年第十六届省赛真题-画展布置
  • SpringMVC 框架核心知识点详解与实战
  • 精益数据分析(41/126):深入解读移动应用商业模式的关键指标与策略
  • linux 高并发 文件句柄数 fs 及 tcp端口数调优
  • 泉州2025年首次网签备案登记的商品住宅并在本年度进行装修、改造及家装物品和材料购置的,在上述补贴额度的基础上上浮2万元,单个产权人补贴最高不超过5万元。
  • VScode中关于Copilot的骚操作
  • ByteArrayOutputStream 类详解
  • 基于yolov11的打电话玩手机检测系统python源码+pytorch模型+评估指标曲线+精美GUI界面
  • 一文说清-什么是强化学习
  • zst-2001 历年真题 程序设计语言
  • 代码随想录算法训练营 Day37 动态规划Ⅴ 完全背包 零钱兑换
  • 【Java ee初阶】多线程(7)
  • C++负载均衡远程调用学习之获取主机信息功能
  • Redis 中简单动态字符串(SDS)的深入解析
  • Vue项目安全实践指南:从输入验证到状态管理的全方位防护
  • 利用WPS创建的Templates目录,快捷生成md文件
  • 【信息系统项目管理师-论文真题】2007下半年论文详解(包括解题思路和写作要点)
  • E-R图作业
  • lambda表达式和方法引用
  • 【Linux】网络基础
  • Python内置函数
  • python打卡day16
  • PyCharm 安装教程