折腾:
【已解决】VMWare的macOS中搭建安卓Android开发环境:adb、aapt等工具
期间,去macOS中安装aapt。
macOS aapt
macOS aapt brew
macOS brew aapt
1、找一份mac下开发环境中的build-tool中的任何一个均可
看来还是需要去安装:
Mac版的Android Studio,然后下载对应的某个版本的安卓的SDK=image=镜像,才有 build-tool?
去看看真机Mac中aapt是在哪里
1 2 3 4 | ✘ xxx@xxx ~ which aapt /Users/xxx/Library/Android/sdk/build-tools/29 .0.2 /aapt xxx@xxx ~ which adb /usr/local/bin/adb |
原来aapt是放在用户的Library下面的Android中的

的确是之前说的,要去下载某个版本的安卓系统镜像,才有build-tools
所以还是要去:
macOS中安装android studio
然后通过android studio安装29.0.2的安卓的SDK ?
或者直接单独下载?
去找找
mac install aapt

是包含adb等工具的:

继续去找aapt:

看起来80多MB,或许包含aapt?
commandlinetools-mac-6609375_latest.zip

解压后,bin中有sdkmanager
但是没aapt
看来aapt是需要用,no gui的sdkmanager去下载的
估计类似于:
1 2 3 | $ tools /bin/sdkmanager --update $ tools /bin/sdkmanager "platforms;android-25" "build-tools;25.0.2" "extras;google;m2repository" "extras;android;m2repository" $ tools /bin/sdkmanager --licenses |
去试试,结果:
【已解决】macOS中安装java开发环境JDK
然后继续试试,结果:
【已解决】Mac中运行sdkmanager报错:错误 找不到或无法加载主类 Shared
继续去安装试试,结果遇到其他错误:
【已解决】macOS中运行sdkmanager报错:Warning Could not create settings
然后:
1 2 | crifanli@crifanlideMac ~ sdkmanager --update [=======================================] 100% Computing updates... |
更新正常。
继续去安装
此处打算安装之前最新的29.0.2
去试试:
1 | sdkmanager "platforms;android-29" "build-tools;29.0.2" "extras;google;m2repository" "extras;android;m2repository" |
是可以开始下载的:
1 2 3 4 5 6 7 8 9 10 11 12 | ~ sdkmanager "platforms;android-29" "build-tools;29.0.2" "extras;google;m2repository" "extras;android;m2repository" License android-sdk-license: ] 10% Computing updates... --------------------------------------- Terms and Conditions This is the Android Software Development Kit License Agreement ... January 16, 2019 --------------------------------------- Accept? (y/N): y [==== ] 10% Downloading android_m2repository_r |

但是速度很慢,半天没进展
所以停止掉,重新给终端中加上代理后,再去下载试试,看看能否加速

用了代理:
1 | export HTTP_PROXY = http: / / 127.0 . 0.1 : 58591 ; export HTTPS_PROXY = http: / / 127.0 . 0.1 : 58591 ; export ALL_PROXY = socks5: / / 127.0 . 0.1 : 51837 |
换成OS2的节点,貌似速度还不错:

不过看来要下载文件很大,超过500KB速度下了一会,才从10%到11%
1 2 | ✘ crifanli@crifanlideMac ~ sdkmanager "platforms;android-29" "build-tools;29.0.2" "extras;google;m2repository" "extras;android;m2repository" [==== ] 11% Downloading android_m2repository_r |
继续下载吧
下了180MB,才12%
难道1%=90MB?
那整个有9000MB=9G左右?
不管,继续下载再说。
或者说,此处的
1 | "extras;google;m2repository" "extras;android;m2repository" |
是下载额外的东西,其实如果只是使用aapt,而无需下载的?
sdkmanager download aapt
1 | sdkmanager "platform-tools" "platforms;android-28" |
貌似可以只下载platform-tools?
那中断掉,只下载
1 | sdkmanager "platforms;android-29" "build-tools;29.0.2" |

这样就不用下载额外东西了
1 2 | ✘ crifanli@crifanlideMac ~ sdkmanager "platforms;android-29" "build-tools;29.0.2" [========== ] 25% Downloading emulator-darwin-685541 |
很快进度就25%了。
然后就只能继续等待了。

1 2 | ✘ crifanli@crifanlideMac ~ sdkmanager "platforms;android-29" "build-tools;29.0.2" [=======================================] 100% Unzipping... android-10 /llvm-rs-c |
终于结束了。
继续:
1 | sdkmanager --licenses |
其中输入y
1 2 3 | crifanli@crifanlideMac ~ sdkmanager --licenses 6 of 7 SDK package licenses not accepted. 100% Computing updates... Review licenses that have not been accepted (y /N )? y |
然后一直输入y即可:
1 2 3 | 。。。 Accept? (y /N ): y All SDK package licenses accepted |
然后看看对应目录的文件有哪些
新增很多文件夹:
1 2 3 4 5 6 7 8 9 10 11 | crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root ll total 0 drwxr-xr-x 3 crifanli staff 96B 10 16 15:05 build-tools drwxr-xr-x 4 crifanli staff 128B 10 16 13:57 cmdline-tools drwxr-xr-x 18 crifanli staff 576B 10 16 14:58 emulator drwxr-xr-x 3 crifanli staff 96B 10 16 14:36 extras drwxr-xr-x 9 crifanli staff 288B 10 16 15:07 licenses drwxr-xr-x 3 crifanli staff 96B 10 16 14:50 patcher drwxr-xr-x 19 crifanli staff 608B 10 16 14:58 platform-tools drwxr-xr-x 3 crifanli staff 96B 10 16 15:04 platforms drwxr-xr-x 14 crifanli staff 448B 10 16 15:02 tools |

以及:
build-tools下面有我们要的:aapt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root ll build-tools /29 .0.2 total 51808 -rw-r--r-- 1 crifanli staff 748K 10 16 15:05 NOTICE.txt -rwxr-xr-x 1 crifanli staff 1.4M 10 16 15:05 aapt -rwxr-xr-x 1 crifanli staff 4.0M 10 16 15:05 aapt2 -rwxr-xr-x 1 crifanli staff 1.9M 10 16 15:05 aarch64-linux-android-ld -rwxr-xr-x 1 crifanli staff 919K 10 16 15:05 aidl -rwxr-xr-x 1 crifanli staff 2.6K 10 16 15:05 apksigner -rwxr-xr-x 1 crifanli staff 4.9M 10 16 15:05 arm-linux-androideabi-ld -rwxr-xr-x 1 crifanli staff 36K 10 16 15:05 bcc_compat -rw-r--r-- 1 crifanli staff 18K 10 16 15:05 core-lambda-stubs.jar -rwxr-xr-x 1 crifanli staff 2.5K 10 16 15:05 d8 -rwxr-xr-x 1 crifanli staff 321K 10 16 15:05 dexdump -rwxr-xr-x 1 crifanli staff 2.5K 10 16 15:05 dx -rwxr-xr-x 1 crifanli staff 4.9M 10 16 15:05 i686-linux-android-ld drwxr-xr-x 6 crifanli staff 192B 10 16 15:05 lib drwxr-xr-x 8 crifanli staff 256B 10 16 15:05 lib64 -rwxr-xr-x 1 crifanli staff 975K 10 16 15:05 llvm-rs-cc -rwxr-xr-x 1 crifanli staff 4.6K 10 16 15:05 mainDexClasses -rw-r--r-- 1 crifanli staff 758B 10 16 15:05 mainDexClasses.rules -rw-r--r-- 1 crifanli staff 310B 10 16 15:05 mainDexClassesNoAapt.rules -rwxr-xr-x 1 crifanli staff 1.8M 10 16 15:05 mipsel-linux-android-ld -rw-r--r-- 1 crifanli staff 17K 10 16 15:05 package.xml drwxr-xr-x 5 crifanli staff 160B 10 16 15:05 renderscript -rw-r--r-- 1 crifanli staff 17B 10 16 15:05 runtime.properties -rw-r--r-- 1 crifanli staff 63B 10 16 15:05 source .properties -rwxr-xr-x 1 crifanli staff 1.4M 10 16 15:05 split - select -rwxr-xr-x 1 crifanli staff 1.7M 10 16 15:05 x86_64-linux-android-ld -rwxr-xr-x 1 crifanli staff 228K 10 16 15:05 zipalign |

以及,另外 platform-tools下面有adb:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root ll platform-tools total 28064 -rw-r--r-- 1 crifanli staff 308K 10 16 14:58 NOTICE.txt -rwxr-xr-x 1 crifanli staff 6.2M 10 16 14:58 adb drwxr-xr-x 4 crifanli staff 128B 10 16 14:58 api -rwxr-xr-x 1 crifanli staff 78K 10 16 14:58 dmtracedump -rwxr-xr-x 1 crifanli staff 1.4M 10 16 14:58 e2fsdroid -rwxr-xr-x 1 crifanli staff 304K 10 16 14:58 etc1tool -rwxr-xr-x 1 crifanli staff 1.6M 10 16 14:58 fastboot -rwxr-xr-x 1 crifanli staff 35K 10 16 14:58 hprof-conv drwxr-xr-x 3 crifanli staff 96B 10 16 14:58 lib64 -rwxr-xr-x 1 crifanli staff 251K 10 16 14:58 make_f2fs -rwxr-xr-x 1 crifanli staff 762K 10 16 14:58 mke2fs -rwxr-xr-x 1 crifanli staff 1.1K 10 16 14:58 mke2fs.conf -rw-r--r-- 1 crifanli staff 17K 10 16 14:58 package.xml -rwxr-xr-x 1 crifanli staff 1.4M 10 16 14:58 sload_f2fs -rw-r--r-- 1 crifanli staff 38B 10 16 14:58 source .properties -rwxr-xr-x 1 crifanli staff 1.3M 10 16 14:58 sqlite3 drwxr-xr-x 6 crifanli staff 192B 10 16 14:58 systrace |

此时,也就可以:
把之前单独用brew安装的commandline的tool,卸载了,而用此处的工具,会更好。
其中对比了下:
1 2 3 4 5 6 7 8 9 10 11 | crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root which adb /usr/local/bin/adb crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root adb --version Android Debug Bridge version 1.0.41 Version 30.0.0-6374843 Installed as /usr/local/bin/adb crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root cd platform-tools crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root/platform-tools . /adb --version Android Debug Bridge version 1.0.41 Version 30.0.4-6686687 Installed as /Users/crifanli/dev/DevTools/android/sdk_root/platform-tools/ . /adb |
可见此处的adb版本更新。
所以去参考之前的:
【已解决】macOS中安装安卓开发工具adb
的
1 | brew cask install android-platform-tools |
卸载之前的
1 | brew uninstall android-platform-tools |
最后是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root/platform-tools brew uninstall android-platform-tools Found a cask named "android-platform-tools" instead. Try brew cask uninstall android-platform-tools Error: No such keg: /usr/local/Cellar/android-platform-tools ✘ crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root/platform-tools brew cask uninstall android-platform-tools ==> Uninstalling Cask android-platform-tools ==> Unlinking Binary '/usr/local/bin/adb' . ==> Unlinking Binary '/usr/local/bin/dmtracedump' . ==> Unlinking Binary '/usr/local/bin/etc1tool' . ==> Unlinking Binary '/usr/local/bin/fastboot' . ==> Unlinking Binary '/usr/local/bin/hprof-conv' . ==> Unlinking Binary '/usr/local/bin/mke2fs' . ==> Purging files for version 30.0.0 of Cask android-platform-tools |
即:
用:
1 | brew cask uninstall android-platform-tools |
卸载的。
然后再去看看:
1 2 | crifanli@crifanlideMac ~ /dev/DevTools/android/sdk_root/platform-tools which adb . /adb |
只能在当前路径才能找到adb了。
然后把此处的路径:
1 2 | /Users/crifanli/dev/DevTools/android/sdk_root/platform-tools /Users/crifanli/dev/DevTools/android/sdk_root/build-tools/29 .0.2 |
都加到PATH中
考虑到本身前缀都是ANDROID_SDK_ROOT
所以最后加到启动脚本中,相关完整内容是:
1 2 3 4 5 6 7 8 9 10 11 12 13 | cat ~ / .zshrc ... export JAVA_HOME = $( / usr / libexec / java_home) export PATH = .:$PATH:$JAVA_HOME / bin export CLASSPATH = $JAVA_HOME / lib / tools.jar:$JAVA_HOME / lib / dt.jar:. export ANDROID_SDK_ROOT = / Users / crifanli / dev / DevTools / android / sdk_root export PATH = $PATH:$ANDROID_SDK_ROOT / cmdline - tools / tools / bin # add adb path export PATH = $PATH:$ANDROID_SDK_ROOT / platform - tools # add aapt path export PATH = $PATH:$ANDROID_SDK_ROOT / build - tools / 29.0 . 2 |
生效
1 | crifanli@crifanlideMac ~ source ~/.zshrc |
后看看版本:
adb
1 2 3 4 5 6 | crifanli@crifanlideMac ~ which adb /Users/crifanli/dev/DevTools/android/sdk_root/platform-tools/adb crifanli@crifanlideMac ~ adb --version Android Debug Bridge version 1.0.41 Version 30.0.4-6686687 Installed as /Users/crifanli/dev/DevTools/android/sdk_root/platform-tools/adb |
aapt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | crifanli@crifanlideMac ~ which aapt /Users/crifanli/dev/DevTools/android/sdk_root/build-tools/29.0.2/aapt crifanli@crifanlideMac ~ aapt --version ERROR: Unknown command '--version' Android Asset Packaging Tool Usage: aapt l[ist] [-v] [-a] file.{zip,jar,apk} List contents of Zip-compatible archive. aapt d[ump] [--values] [--include-meta-data] WHAT file.{apk} [asset [asset ...]] strings Print the contents of the resource table string pool in the APK. badging Print the label and icon for the app declared in APK. permissions Print the permissions from the APK. resources Print the resource table from the APK. configurations Print the configurations in the APK. xmltree Print the compiled xmls in the given assets. xmlstrings Print the strings of the given compiled xml assets. 。。。 |
至此,aapt终于可用了。
【总结】
此处,macOS中安装aapt:
思路:
aapt属于某个安卓的SDK镜像包中的工具
位置往往是:
1 | xxx /build-tools/aapt |
xxx=25.0.2 / 29.02 等等
所以想要安装aapt,则需要安装整个的某个版本的安卓的SDK
可以通过Android Studio中SDK的安装
也可以用非界面的命令行方式,用sdkmanager去安装
步骤:
此处用命令行工具sdkmanager去安装
1、安裝sdkmanager
从官网
下载到:
commandlinetools-mac-6609375_latest.zip
先找个文件夹,用作:ANDROID_SDK_ROOT
比如:/Users/crifanli/dev/DevTools/android/sdk_root
在其中新建文件夹,名字一定要叫做:cmdline-tools
然后把commandlinetools-mac-6609375_latest.zip解压得到的tools目录,放到cmdline-tools中
再去把ANDROID_SDK_ROOT和sdkmanager所在目录加到环境变量
即
1 | vi ~/.zshrc |
把
1 2 | export ANDROID_SDK_ROOT= /Users/crifanli/dev/DevTools/android/sdk_root export PATH=$PATH:$ANDROID_SDK_ROOT /cmdline-tools/tools/bin |
放到脚本最后。
如此,才能正常使用sdkmanager。
2、再去用sdkmanager安装aapt
(最好先)更新sdkmanager到最新版本:
1 | sdkmanager --update |
再去安装,具体某个版本的安卓的SDK,即build-tools
比如此处选择安装最新版 29.0.2
1 | sdkmanager "platforms;android-29" "build-tools;29.0.2" |
需要等待很长一段时间,具体长度取决于你的网络。
注:此处用代理
1 | export HTTP_PROXY = http: / / 127.0 . 0.1 : 58591 ; export HTTPS_PROXY = http: / / 127.0 . 0.1 : 58591 ; export ALL_PROXY = socks5: / / 127.0 . 0.1 : 51837 |
加速下载,速度还行。
都下载安装后,即可找到我们要的aapt了:
1 | /Users/crifanli/dev/DevTools/android/sdk_root/build-tools/29 .0.2 /aapt |
注:
其中:
1 | "platforms;android-29" |
是可选的,如果加了,安装后,会有platform-tools目录,其中有adb
1 | /Users/crifanli/dev/DevTools/android/sdk_root/platform-tools/adb |
最后使用之前要同意协议:
1 | sdkmanager --licenses |
然后一直输入y表示同意。即可。
再去添加路径到环境变量中,确保后续任意路径下都可以启动aapt(和adb)等工具。
即编辑启动脚本:
1 | vi ~/.zshrc |
把相关路径加到环境变量中,即把
1 2 3 4 | # add adb path export PATH = $PATH:$ANDROID_SDK_ROOT / platform - tools # add aapt path export PATH = $PATH:$ANDROID_SDK_ROOT / build - tools / 29.0 . 2 |
放到文件最后。
注:
贴出更新后的.zshrc中相关完整配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 | # java related export JAVA_HOME = $( / usr / libexec / java_home) export PATH = .:$PATH:$JAVA_HOME / bin export CLASSPATH = $JAVA_HOME / lib / tools.jar:$JAVA_HOME / lib / dt.jar:. # sdkmanager related export ANDROID_SDK_ROOT = / Users / crifanli / dev / DevTools / android / sdk_root export PATH = $PATH:$ANDROID_SDK_ROOT / cmdline - tools / tools / bin # add adb path export PATH = $PATH:$ANDROID_SDK_ROOT / platform - tools # add aapt path export PATH = $PATH:$ANDROID_SDK_ROOT / build - tools / 29.0 . 2 |
供参考。
转载请注明:在路上 » 【已解决】macOS中安装安卓开发工具aapt