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:52

You can accept all the license by executing the following command:

 sdkmanager --licenses

This will prompt you through each licenses you haven't accepted yet and you can just enter y to accept each of them.

查看更多
若你有天会懂
3楼-- · 2019-01-01 06:54

I have encountered this with the alpha5 preview.

Jake Wharton pointed out to me that you can currently use

mkdir -p "$ANDROID_SDK/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"

to recreate the current $ANDROID_HOME/license folder on you machine. This would have the same result as the process outlined in the link of the error msg (http://tools.android.com/tech-docs/new-build-system/license).

The hashes are sha1s of the licence text, which I imagine will be periodically updated, so this code will only work for so long :)

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

I was surprised at first that this didnt work out of the box, even when I had accepted the licenses for the named components via the android tool, but it was pointed out to me its the SDK manager inside AS that creates the /licenses folder.

I guess that official tools would not want to skip this step for legal reasons.

Rereading the release notes it states

SDK auto-download: Gradle will attempt to download missing SDK packages that a project depends on.

Which does not mean it will work if you have not installed the android tools yet and have already accepted the latest license(s).

EDIT: Saying that, it still does not work on my test gubuntu box until I link the SDK up to AS. CI works fine though - not sure what the difference is...

查看更多
查无此人
4楼-- · 2019-01-01 06:54

I solved this problem by creating a public git repo with the accepted license files. Then I use wget to fetch these licenses on any machine I need into a [sdk-dir]/licenses directory before running ./gradlew to build my project.

查看更多
大哥的爱人
5楼-- · 2019-01-01 06:54

Finally, this 2 simple steps worked for me on windows 10.

1) Make sure you update your android build tools and api. On your Android Sdk Just click on install packages to install available updates.

2) Start your Android Studio and you'll be prompted to install the reqiured build tools for the already updated api and tools, This will install the build tools properties including the licences and your done.

查看更多
人间绝色
6楼-- · 2019-01-01 06:55

For an error message about SDK api number 25:

android update sdk --no-ui --all --filter build-tools-25.0.1,android-25,extra-android-m2repository

查看更多
栀子花@的思念
7楼-- · 2019-01-01 06:55

I finally found a solution on Windows, to have a real silent and automatic install:

On Windows, the following syntax doesn't work:

echo y | sdkmanager --licenses

It seems the "y" aren't correctly sent to the java program called in the batch.

The workaround is to create a file file-y.txt with several "y", one by line, and to use

call sdkmanager --licenses < file-y.txt

This will create the needed files in the licenses directory. The problem is probably related to the use of BufferedReader in Java

查看更多
登录 后发表回答