Automatically accept all SDK licences

2019-01-01 06:01发布

Since gradle android plugins 2.2-alpha4:

Gradle will attempt to download missing SDK packages that a project depends on

Which is amazingly cool and was know to be a JakeWharton project.

But, to download the SDK library you need to: accept the license agreements or gradle tells you:

You have not accepted the license agreements of the following SDK components: [Android SDK Build-Tools 24, Android SDK Platform 24]. Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager. Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

And this is a problem because I would love to install all sdk dependencies while doing a gradle build.

I am looking for a solution to automatically accept all licenses. Maybe a gradle script ? Do you have any ideas ?

Thanks!

[EDIT]

A solution was to execute:

android update sdk --no-ui --filter build-tools-24.0.0,android-24,extra-android-m2repository

And install it manually, but it is the gradle's new feature purpose to do it.

[EDIT 2]

A better solution is to use the sdkmananger:

yes | sudo sdkmanager --licenses

30条回答
路过你的时光
2楼-- · 2019-01-01 06:56

cd $ANDROID_HOME/tools/bin ./sdkmanager --update

查看更多
刘海飞了
3楼-- · 2019-01-01 06:57

The android tool is deprecated and you should use the sdkmanager instead. sdkmanager also writes the licenses file when you first accept it. The license changes depending on which SDK you are using so even though the command

echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"

works on some systems. It won't work on all. Some SDK installs expect to license file to end without a newline in the file so try adding a -n to the echo command.

echo -n -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"

If that isn't working you can try using the base64 encoding instead.

So to discover my license:

$> rm ${ANDROID_HOME}/
$> unzip tools_r25.2.3-linux.zip -d ${ANDROID_HOME}
$> ${ANDROID_HOME}/tools/bin/sdkmanager "system-images;android-23;default;x86_64"

It'll prompt you to accept the license. After accepting it'll copy it to ${ANDROID_HOME}/licenses/android-sdk-license. To ensure you always get exactly what is written use base64.

$> base64 ${ANDROID_HOME}/licenses/android-sdk-license
Cjg5MzNiYWQxNjFhZjQxNzhiMTE4NWQxYTM3ZmJmNDFlYTUyNjljNTU=

Then you can use base64 -d recreate the file exactly.

$> echo Cjg5MzNiYWQxNjFhZjQxNzhiMTE4NWQxYTM3ZmJmNDFlYTUyNjljNTU= | base64 -d > ${ANDROID_HOME}/licenses/android-sdk-license

You can verify if the file written is what is expected by running a sha1sum on it.

$> sha1sum ${ANDROID_HOME}/licenses/android-sdk-license
da6b80c9c47b41c0bf7032938e7137a58a3dc249
查看更多
只若初见
4楼-- · 2019-01-01 06:58

I tried all the above command on windows 10 machine but the solution was to use the SDKMANAGER to check and accept licenses buy installing missing versions

enter image description here

查看更多
高级女魔头
5楼-- · 2019-01-01 07:00

Unfortunately the way as OP originally solved it does not always work. If you find from the error message what is your builds current build-tools version. It could be that it is a higher version of build-tools that is missing. In that case you need to manually start SDK Manager and add the build-tools and accept license.

Per OP instructions, it look as follows.

$ ./gradlew build

 
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

NOTE: 2017-04-16

The android tool has now been deprecated in favor of the new sdkmanager. Please see Joe Lawson's answer and subsequent posts from March (2017) and onward.

Then adjust you command as follows:

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.

Running this again, still do not make Gradle happy. So manual acceptance is the only solution until someone come up with something better. (Please do!)

查看更多
不再属于我。
6楼-- · 2019-01-01 07:00

I navigate to:

/usr/lib/android-sdk/licenses

and I typed in terminal:

echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_SDK/licenses/android-sdk-license"

With root permission. And it works for me now.

查看更多
与君花间醉酒
7楼-- · 2019-01-01 07:01

if you run yes | sdkmanager --licenses, then we print content of $ANDROID_HOME/licenses/android-sdk-license,

we will get this

# cat $ANDROID_HOME/licenses/android-sdk-license

8933bad161af4178b1185d1a37fbf41ea5269c55

d56f5187479451eabf01fb78af6dfcb131a6481e

For GitLab CI, to accept Android SDK Build-Tools 26.0.2 licenses, you need to run this

before_script:
  - mkdir -p $ANDROID_HOME/licenses
  - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license
  - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> $ANDROID_HOME/licenses/android-sdk-license
查看更多
登录 后发表回答