因为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脚本? 你有什么想法吗?


当前回答

我可以找到两种方法来解决这个问题。

Update sdk tools with command window by accepting licence agreement as follows, just change the version according to your need. android update sdk --no-ui --filter build-tools-25.0.2,android-25,extra-android-m2repository Second approach is copying licence folders to Android root directory. Goto your development machine open Android Studio. Find your sdk location from Project Structure menu. (C:\Users\UserName\AppData\Local\Android\sdk). Under that directory there must be a licence folder. Copy that folder with the content. Paste that folder in your Jenkins server machine (or where you face with this problem) under android sdk root folder. (C:\Users\UserName.jenkins\tools\android-sdk)

其他回答

cd $ ANDROID_HOME /工具/ bin 是| ./sdkmanager——update

or

是| $ANDROID_HOME/tools/bin/sdkmanager——update

我在使用Cordova时也犯了同样的错误。

问题是由于我通过Android Studio和apt安装Android - Sdk adb安装Android Sdk。Cordova正在调用通过apt安装的文件,而不是我的主目录中的文件。

当我在bash中更改SDK的路径时,它就工作了:

# Change path
export ANDROID_HOME="$HOME/Android/Sdk/"
echo "Android home = $ANDROID_HOME"
# Accept licenses
eval "${ANDROID_HOME}/tools/bin/sdkmanager --licenses"
# Run Cordova
cordova build android

然后我删除了不再使用的系统文件:apt remove android-sdk adb。

注意:这仅适用于Mac用户

我也有同样的问题,但没有一个答案张贴帮助,因为在库/Android/sdk中没有工具文件夹。(我在Mac OS 10.14.4上使用Android 3.6.3)

以下步骤帮助我克服了许可问题错误:

Open Android Studio 按cmd + shift + a,打开Actions弹出窗口。 搜索SDK管理器并点击进入打开。 这将为Android SDK打开弹出窗口。选择其他Android版本,除了已经安装的版本。(在我的情况下,Android 10.0已经安装,所以我选择了Android 9.0) 然后选择Apply按钮。这将安装相应的SDK。

现在运行你的应用程序,它应该工作没有任何例外。

如果您正在使用Flutter,只需运行:

flutter doctor --android-licenses 

并接受所有需要的许可。

不幸的是,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开心。所以手动验收是唯一的解决方案,直到有人想出更好的方法。(请做!)