我想从命令行设置Android开发环境,遇到以下问题:

wget http://dl.google.com/android/android-sdk_r22.0.5-linux.tgz

解压完成后,运行

tools/android update sdk --no-ui

但是,它跑起来太慢了

Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml

结果是在文件夹build-tools中什么都没有,我想要的是apapt和apkbuilder,因为我想从命令行构建apk而没有ant。


当前回答

我尝试了这个更新所有,它工作!

echo y | $ANDROID_HOME/tools/android update sdk --no-ui

其他回答

从developer.android.com下载android SDK(目前windows操作系统的文件大小为149mb)。值得注意的是,android已经删除了sdkmanager GUI,但在位于tools文件夹内的bin文件夹中有一个sdkmanager的命令行版本。

When inside the bin folder, hold down the shift key, right click, then select open command line here. Shift+right click >> open command line here. When the command line opens, type sdkmanager click enter. Then run type sdkmanager (space), double hyphen (--), type list sdkmanager --list (this lists all the packages in the SDK manager) Type sdkmanager (space) then package name, press enter. Eg. sdkmanager platform-tools (press enter) It will load licence agreement. With options (y/n). Enter y to accept and it will download the package you specified.

如需更多参考,请参考这里的官方文件

我希望这能有所帮助。:)

我就遇到了这个问题,所以我最终通过读取和解析可用工具列表来编写了一行bash dirty解决方案:

 tools/android update sdk -u -t $(android list sdk | grep 'Android SDK Build-tools' | sed 's/ *\([0-9]\+\)\-.*/\1/')

大多数答案似乎忽略了这样一个事实,即您可能需要在没有超级用户权限的无头环境中运行更新,这意味着脚本必须自动回答所有y/n许可提示。

下面是一个例子。

FILTER=tool,platform,android-20,build-tools-20.0.0,android-19,android-19.0.1

( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \
    | android update sdk --no-ui --all \
    --filter ${FILTER}

No matter how many prompts you get, all of those will be answered. This while/sleep loop looks like simulation of the yes command, and in fact it is, well almost. The problem with yes is that it floods stdout with 'y' and there is virtually no delay between sending those characters and the version I had to deal with had no timeout option of any kind. It will "pollute" stdout and the script will fail complaining about incorrect input. The solution is to put a delay between sending 'y' to stdout, and that's exactly what while/sleep combo does.

expect在一些linux发行版上默认是不可用的,我没有办法将它作为我的CI脚本的一部分安装,所以必须使用最通用的解决方案,没有什么比简单的bash脚本更通用的了,对吗?

事实上,我在博客上写过(NSBogan),如果你感兴趣,可以在这里查看更多细节。

在不安装整个android studio的情况下安装android环境:

下载JDK(版本大于8) 从https://gradle.org/install/下载gradle 从https://developer.android.com/studio下载命令行工具,只下载命令行工具 设置必要的环境变量 下载必要的SDK工具

我尝试了这个更新所有,它工作!

echo y | $ANDROID_HOME/tools/android update sdk --no-ui