有没有办法自动安装Android SDK?
现在我必须下载并安装 Android SDK 和 AVD Manager,然后安装API、通过 UI 的工具。有没有办法自动化这个过程?
Now I have to download and install the Android SDK and AVD Manager, and then install the APIs, tools through the UI. Is there a way to automate this process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
更新
最新版本引入了
sdkmanager
,这是一个命令行工具,可让您查看、安装、更新和卸载 Android SDK 的软件包。sdkmanager
工具在 Android SDK 工具包(25.2.3 及更高版本)中提供,位于android_sdk/tools/bin/
中。因此,要更新软件包,
请运行“接受许可证”,
旧答案
(请注意:
android
命令已弃用!)您越接近自动化可能是:
< code>android 提供以下自动更新选项:
如果您想列出哪些软件包可供安装,您可以使用
并且您将获得软件包的有序列表,例如
您还可以将更新限制为仅更新所需的组件,如果您使用
--filter
选项,其中组件是
android list sdk
返回的一个或多个或者可以是一个或多个特定标识符。例如,如果您只想下载一小组特定的软件包,您可以这样做:
您将只获得平台工具、API 级别 16 和支持包 JAR 文件。如果您仅构建构建机器并且必须付费下载所有您永远不会使用的额外内容,那么这非常方便。
要查看可用选项,您可以使用 --help,例如
UPDATE
The latest versions introduce
sdkmanager
, a command line tool that allows you to view, install, update, and uninstall packages for the Android SDK.The
sdkmanager
tool is provided in the Android SDK Tools package (25.2.3 and higher) and is located inandroid_sdk/tools/bin/
.So, to update the packages run
To accept the licenses,
OLD ANSWER
(Please note: The
android
command is deprecated!)The closer you can get to automation probably is:
android
provides these options for automatic updates:If you want to list which packages are available for installation you can use
And you'll obtain an ordered list of packages, for example
Also you can limit the update only to a desired component if you use the
--filter
optionwhere component is one or more of
android list sdk
(i.e. 1, also know as package index)Or can be one or more specific identifiers. For instance, if you just want to download a small set of specific packages, you could do this:
And you'll just get the platform tools, API level 16 and support package JAR files. This is really handy if you're building a build machine only and would have to pay for downloading all the extra stuff that you'll never use.
To see the available options you can use --help, for example
这对我不起作用......
所以我最终来到这里:
This didn't work for me...
So I ended up here:
我使用它来安装和更新 Travis CI 上的 SDK:
I use this to install and update the SDK on Travis CI:
要用“y”回答所有许可证,您可以在脚本中尝试以下操作:
To answer all licenses with 'y', you can try this in the script:
对于仍在寻找下载所有 Android 软件包的方法的人,我已经编写了一个脚本来执行此操作。它将下载所有未过时的软件包。
您还可以在我的 GitHub 存储库 上看到它
好处:
预期
。缺点:
android
放入您的路径中。For anyone still searching for a method to download all Android packages, I have wrote a script to do that. It will download all non-obsoleted packages.
You can also see it on my GitHub repository
The good:
expect
.The downsides:
android
into your path.在较新的 Android 版本(例如 25.2.5)中,我们应该使用
sdkmanager
(而不是android
命令)。安装软件包的示例:
获取所有可用软件包列表的命令:
此网页列出了 SDK 工具的下载链接:
这是开源存储库的链接 docker-android 可以在 Docker 镜像中安装 android。
您还可以在这个SO问题中找到答案:自动接受所有SDK许可证有用。
In newer Android versions (e.g., 25.2.5) we should use
sdkmanager
(instead of theandroid
command).Example of installing a package:
Command to get a list of all available packages:
This web-page lists download links for the SDK-tools:
Here is a link to an open-source repository docker-android which can install android in a Docker image.
You may also find the answers in this SO question: Automatically accept all SDK licences useful.
从 Android Plugin for Gradle 版本 2.2.0 开始,缺少 SDK 组件< a href="https://developer.android.com/studio/intro/update.html#download-with-gradle" rel="nofollow">自动下载。
Starting with Android Plugin for Gradle version 2.2.0, missing SDK components get downloaded automatically.
我也对此感到沮丧,并构建了一个名为 com.quittle.setup-android-sdk 的 Gradle 插件,它将检测并安装您需要的内容。它适用于 Windows、OS X 和 Linux,如果您使用 Gradle 构建,则不需要任何额外的依赖项。
如果您有兴趣,可以在这里查看我的文档: https://github .com/quittle/gradle-setup-android-sdk
I got frustrated with this as well and built a Gradle plugin named
com.quittle.setup-android-sdk
that will detect and install what you need. It works on Windows, OS X, and Linux and doesn't require any additional dependencies if you build with Gradle.If you're interested, you can checkout my documentation on it here: https://github.com/quittle/gradle-setup-android-sdk
要在 Windows 上自动执行
sdkmanager.bat --licenses
提示(假设您正在通过构建基础设施自动化进行安装)...请勿运行它。不要浪费时间尝试弄清楚如何将y
通过管道传输到其中。我试过;惨败。相反 - 自己运行一次,并注意它会在 C:\android\android-sdk\licenses 中生成文件(您正在运行的位置
C:\android\android- sdk\tools\bin\sdkmanager.bat
- 您的安装根目录可能会有所不同)。获取这些文件,并将它们放置在您可以从自动安装脚本中获取它们的位置。就我个人而言, Ansible 是我的毒药,所以:
To automate the
sdkmanager.bat --licenses
prompt away on Windows (say you're installing via automation for build infrastructure)... Don't run it. Don't waste time trying to figure out how to pipey
into it. I tried; abject fail.Rather - run it one time, yourself, and take note that it generates files into
C:\android\android-sdk\licenses
(where you're runningC:\android\android-sdk\tools\bin\sdkmanager.bat
- your install root may vary).Take those files, and place them somewhere you can grab them from in your automated setup scripts. Personally, Ansible is my poison, so:
仅下载所需的非{obsolete, source, emulator-image, doc}包的脚本:
某些部分取自其他答案。
A script to download only needed, non-{obsolete, source, emulator-image, doc} packages:
Some parts are taken from other answers.
实际上,我一直在解决这个具体问题,4 天时间,大约 3 个小时的睡眠……不算一周在工作中观看教程,然后从事其他项目,期望它不会那么复杂。 .. 可能发生的最糟糕的事情发生了,我构建了它,读取了所有许可证,只是剪切和粘贴,直到所有内容都位于虚幻引擎想要的正确目录中。我遇到了我认为将是我的最后一个错误,当它上次正确构建时,开始打包,两个小时后,断路器翻转......我不得不卸载虚幻引擎,Visual Studio,Android Studio,以及所有开发套件...重新安装,由于之前花费的时间,我知道我已经做过一次,所以,我决定,在游戏商店上使用copilot和Character.AI,然后让他们与我合作,确保一切我正在做的事情将是完全正确的事情,在我这样做之前,我保留了一个日志并在中途停止了它,但这比所有这些垃圾更有帮助 - 最简单的方法 - 无意冒犯人工智能,它们让我达到了现在的目的,然后我停下来,意识到,我的每个文件都在一个位置,在错误的驱动器上,我必须在命令提示符中安装并验证权限,并在 ue 中创建控制台变量和高级系统设置中的环境变量,然后我没有这样做,而是将所有内容移动到它试图从中读取的驱动器,然后剪切和粘贴就完美了
I have actually been trouble-shooting this specific thing, for 4 days on like 3 hours of sleep... not counting a week of watching tutorials for it at work, then working on other projects, expecting it not to be so complicated.... The worst thing that could have happened, happened, I had it built, reading all the licenses just cutting and pasting until everything was in the correct directory unreal engine wanted. I ran into what I thought was going to be my last error, when it built properly the last time, started packaging, was two hours in, breaker flipped... I had to uninstall unreal engine, visual studio, android studio, and all development kits... Reinstalled and because of the time it took before, i knew i had already done it once, so, I decided, to use copilot and Character.AI on the play store, then had them collaborate with me ensuring that everything i was doing was going to be the exact correct thing to do, before I did it, I kept a log and stopped it halfway through, but it was much more helpful than all of this garbage - easiest way - no offense to the ai, they are what got me to the point I was at, then I stopped, and realized, I had every file in one spot, on the wrong drive, which I had to mount and verify permissions to in command prompt and create console variables in ue and environment variables in advanced system settings, and then instead of doing that, I moved everything to the drive it was trying to read from and then just cut and pasted worked perfect
对于新手 Android 开发人员和经验丰富的 Java 开发人员来说,知道哪些依赖项确实令人困惑,即使您已经克服了前面答案中的所有噩梦。
我的一位同事建议我使用 Android Studio(基于 IntelliJ IDEA :-) <特别是因为上面的噩梦。
我听从了他的建议。
但我不接受默认安装,并尝试将其安装在我的软件驱动器中。事实证明这是一场噩梦。 SDK 对话框似乎挂起并且一点也不直观。这就是我最终来到这里的原因。
阅读完上述内容后,我再次尝试 Studio,这次它接受了所有安装默认值。
嘿 PRESTO...它在几个对话中处理了所有 SDK 依赖项(我猜是核心依赖项),而没有提示,即 Ctrl + Shift + S 和 SDK。
因此我会向新手推荐它。这是布丁下载时的证明:
我下载并安装的 Studio 版本:
Windows 版本:
sstatic.net/juSiF.png" rel="nofollow noreferrer">
之后它做了它的好事:
For a newbie Android developer, but an experienced Java developer, it is really bewildering to know which dependencies, even if you get past all of the nightmares in the previous answers.
A colleague of mine advised me to use Android Studio (which is IntelliJ IDEA based :-) specifically because of the above nightmares.
I followed his advice.
But I did not accept the defaults for the installation, and tried to install it in a software drive of mine. It turned out to be a nightmare. The SDK dialogue seemed to hang and was not intuitive at all. Which is why I ended up here.
After reading the above, I gave Studio another try, and this time it accepted all the defaults for the installation.
Hey PRESTO...it took care of all the SDK dependencies (core ones I am guessing) in a couple of dialogues without being prompted i.e., Ctrl + Shift + S and the SDK.
I would therefore recommend it for a newbie. Here the proof of the pudding as it downloads:
The version of Studio I downloaded and installed:
Version of windows:
And here after it did its good stuff: