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

You can also just execute

$ANDROID_HOME/tools/bin/sdkmanager --licenses

Or for Windows execute

%ANDROID_HOME%/tools/bin/sdkmanager --licenses

查看更多
倾城一夜雪
3楼-- · 2019-01-01 06:35

I had the same error while using Cordova.

The problem was due to the fact that I installed Android Sdk through Android Studio and through apt with apt install android-sdk adb. And Cordova was calling the files installed through apt instead of the files in my home directory.

It worked once I changed the path to SDK in bash:

# 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

Then I removed the system files that weren't used anymore: apt remove android-sdk adb.

查看更多
回忆,回不去的记忆
4楼-- · 2019-01-01 06:36

For the new sdkmanager utility:

yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;24.0.3"

There's a bit of a delay between yesses, so the command could hang with the license showing for a while, but it doesn't require human intervention.

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

Copy the entire licenses/ directory and paste it into the Android SDK home directory on the machine where you wish to build your projects.

https://developer.android.com/studio/intro/update.html#download-with-gradle

this resolved the issue for me

查看更多
牵手、夕阳
6楼-- · 2019-01-01 06:38

On Mac OSX, navigate to the sdk/tools/bin

Then run ./sdkmanager --licenses, and accept all the licenses.

查看更多
只靠听说
7楼-- · 2019-01-01 06:38

FOR REACT NATIVE APPs:

If you are having this problem for a React Native app, in addition to above mentioned steps, make sure you have the local.properties file in the android directory(AppName/android) of your app which points to your 'sdk' directory:

sdk.dir=/PATH_TO_SDK/
查看更多
登录 后发表回答