因为gradle android插件2.2-alpha4:
Gradle会尝试下载项目中缺失的SDK包
取决于
这非常酷,是杰克·沃顿的一个项目。
但是,要下载SDK库,你需要:接受许可协议,否则gradle会告诉你:
您还没有接受以下SDK的许可协议
组件:[Android SDK Build-Tools 24, Android SDK Platform 24]。
在构建项目之前,您需要接受许可证
协议并完成缺少组件的安装
使用Android Studio SDK管理器。或者,学习如何
将许可证协议从一个工作站转移到另一个工作站,转到
http://d.android.com/r/studio-ui/export-licenses.html
这是一个问题,因为我想在做gradle构建时安装所有的sdk依赖。
我正在寻找一个解决方案,自动接受所有的许可证。也许是一个gradle脚本?
你有什么想法吗?
不幸的是,OP最初解决它的方式并不总是有效。
如果从错误消息中找到构建的当前构建工具版本。可能是缺少了更高版本的构建工具。在这种情况下,您需要手动启动SDK管理器并添加构建工具并接受许可证。
根据OP指令,它如下所示。
$ ./gradlew构建
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
[Android SDK Build-Tools 24.0.2].
...
BUILD FAILED
注意:2017-04-16
android工具现在已经弃用,取而代之的是新的sdkmanager。请参阅乔·劳森的回答以及2017年3月及以后的帖子。
调整命令如下:
android update sdk --no-ui --filter build-tools-24.0.2,android-24,extra-android-m2repository
Refresh Sources:
Fetching https://dl.google.com/android/repository/addons_list-2.xml
Validate XML
Parse XML
Fetched Add-ons List successfully
Refresh Sources
Fetching URL: https://dl.google.com/android/repository/repository-11.xml
Validate XML: https://dl.google.com/android/repository/repository-11.xml
Parse XML: https://dl.google.com/android/repository/repository-11.xml
...
Error: Ignoring unknown package filter 'build-tools-24.0.2'
-------------------------------
License id: android-sdk-license-xxxxxxxx
Used by:
- SDK Platform Android 7.0, API 24, revision 2
- Android Support Repository, revision 39
-------------------------------
...
November 20, 2015
Do you accept the license 'android-sdk-license-xxxxxxxx' [y/n]: y
Installing Archives:
Preparing to install archives
Downloading SDK Platform Android 7.0, API 24, revision 2
Installing SDK Platform Android 7.0, API 24, revision 2
Installed SDK Platform Android 7.0, API 24, revision 296%)
Downloading Android Support Repository, revision 39
Installing Android Support Repository, revision 39
Installed Android Support Repository, revision 3999%)
Done. 2 packages installed.
再运行一次,仍然不能让Gradle开心。所以手动验收是唯一的解决方案,直到有人想出更好的方法。(请做!)
WINDOWS的解决方案
打开终端Windows电源外壳
进入Android SDK文件夹
通常这个文件夹可以在C:\Users(your-windows-user)\AppData\Local\Android\Sdk\tools\bin中找到
从“....”开始“\Sdk”文件夹进入“\tools\bin”
最后路径C:\Users(your-windows-user)\AppData\Local\Android\Sdk\tools\bin
使用ls命令验证sdkmanager.bat已经就位
执行下一个命令
然后终端会显示7个文件,你需要在每个文件中输入yes
我解决了这个问题,因为我不能使用UI。它用于Azure中的管道。(Windows)没有一个答案对我有用,但是@ mobyfr发的file-y.t xtxt给我指明了正确的方向
这适用于新安装。你根本不需要使用Android Studio或任何UI。
Create C:\AndroidTest
Create ENV variable called ANDROID_SDK_TOOLS with path from #1
Create ENV variable called JAVA_HOME and give it the folder path
open up CMD in Admin mode and go to C:\Android
curl --output test.zip https://dl.google.com/android/repository/commandlinetools-win-8092744_latest.zip
Use your favorite command line to extract the zip into the same folder
Navigate to the bin folder ( cmdline-tools\bin )
In this folder, create a file like mentions in another answer. file-y.txt and add a bunch of y's. Basically type y on each line. I did 20. So you have 20 lines with 1 y on each
sdkmanager "platform-tools" "platforms;android-29" --sdk_root="C:\AndroidTest\cmdline-tools\bin" < file-y.txt
这将下载所有你需要的sdk,而不需要gradle/AndroidStudio/Xamarin。对于管道来说,动态下载整个SDK支持非常棒
如果你有问题,你需要输入sdkmanager——licenses——sdk_root="C:\AndroidTest\cmdline-tools\bin" < file-y.txt
但是,我对此表示怀疑。
我在alpha5预览版中遇到过这种情况。
杰克·沃顿告诉我的,你现在可以用
mkdir -p "$ANDROID_SDK/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"
重新创建当前的$ANDROID_HOME/license文件夹。这将产生与错误msg (http://tools.android.com/tech-docs/new-build-system/license)链接中概述的过程相同的结果。
哈希是许可证文本的sha1s,我想它会定期更新,所以这段代码只能工作这么长时间:)
并手动安装它,但这是gradle的新功能的目的。
一开始我很惊讶,这并没有开箱即用,即使当我通过android工具接受了命名组件的许可证,但它向我指出它的SDK管理器在AS内创建/许可证文件夹。
我猜官方工具出于法律原因不会跳过这一步。
重读发布说明
SDK自动下载:Gradle会尝试下载项目所依赖的丢失的SDK包。
这并不意味着它将工作,如果你还没有安装android工具,并已经接受了最新的许可证(s)。
编辑:话虽如此,在我将SDK链接到AS之前,它仍然不能在我的测试gubuntu盒子上工作。不过CI工作得很好-不知道有什么不同…