39
votes

I'm trying to run the command ionic build android --release to build the apk but i am getting this error

Total time: 1.767 secs Error: cmd: Command failed with exit code 1 Error output: FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'android'.

    You have not accepted the license agreements of the following SDK components: [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

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Picked up _JAVA_OPTIONS: -Xmx512M

18

18 Answers

47
votes

Install the license:

mkdir "%ANDROID_HOME%\licenses"

echo |set /p="8933bad161af4178b1185d1a37fbf41ea5269c55" > "%ANDROID_HOME%\licenses\android-sdk-license"

19
votes

In Command Prompt, go to ANDROID_HOME\tools\bin

Then run the command, sdkmanager --licenses

Accept the licenses you want when it is prompted.

18
votes

Install Platform 24 (Android 7) solved this problem

12
votes

I solved it by installing the Android SDK Platform 24 without the Android SDK manager.

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

*Cordova CLI 6.4.0 / Windows 10

5
votes
  1. Go to C:\Users\<UserName>\AppData\Local\Android\Sdk\tools\bin
  2. Run command ./sdkmanager.bat --licenses
  3. accept license

Worked for me

2
votes

This worked for me under ubuntu :

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

source: Dori's answer to automatically-accept-all-sdk-licences

2
votes

Above peter wang's answer worked for me after setting the ANDROID_HOME environment variable. in my case ANDROID_HOME was C:\Users\YourUserName\AppData\Local\Android\android-sdk

After that below commands resulted in a successful build.

mkdir "%ANDROID_HOME%\licenses"
echo |set /p="8933bad161af4178b1185d1a37fbf41ea5269c55" > "%ANDROID_HOME%\licenses\android-sdk-license"
2
votes

My software:

Ubuntu 16.04.2 LTS
Gradle 3.5
java version "1.8.0_131"
$ANDROID_HOME = ~/AndroidSDK

Working solution:

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

of course you should use your version of build-tools.

Source:

Automatically accept all SDK licences

1
votes

You will run into an issue like this whenever your Android Studio's packages are outdated, as building will occur in the latest stable releases. To fix, do the following:

Android Studio > Preferences > Appearance & Behavior > System Settings > Android SDK Tick the latest Android versions (or what you need), click Apply. It's at this point where Android will ask you to agree to its license(s) and the updated version(s) will be installed.

Now you can Ionic / Cordova / PhoneGap build / run.

1
votes

If you are having issues coming from a newer version of Android SDK then change your target version in your config.xml.

Next, open Android Studio>Configure>SDK Manager

Check the version you need for 24 use 7.0 and check it. Then install it and try to build again.

0
votes

I had the same issue and I used @peters.Wang answer to generate license and placed license folder inside sdk folder.

Thanks to @peters.Wang

enter image description here

0
votes

Install sdk 25 and accept the license from android studio. That solved my issues.

0
votes

I've solved my problem with this.

mkdir "%ANDROID_HOME%\licenses"

echo |set /p="8933bad161af4178b1185d1a37fbf41ea5269c55" > "%ANDROID_HOME%\licenses\android-sdk-license"
0
votes

You have to follow the helper text after

You have not accepted the license agreements of the following SDK components: in this situation you have to install [Android SDK Platform 24]. in fact the helper text in bracket [] drives you to the right way.

0
votes

I solved the problem by checking file android-sdk-licenses in Installed ANdroid path for ex my path G:\Android\sdk\licenses with the same file present in this directory C:\Users\Ashutosh\AppData\Local\Android\Sdk\licenses copy all the licenses if more than one :)

0
votes

I had same situation and all of the above suggestion did not work because either my installation and component folder names are different or the files are in different places.

I had old installation of Android Studio in C and new in E. I had uninstalled the old version but Android studio did not clear all files and reset my Env. Variable. So I simply did following

1) Searched for this file: android-sdk-license

2) See if above file is in folder Licenses surrounded by other folders like add-ons, build-tools, emulator etc.

3) Then make sure ANDROID_HOME is pointing to this parent folder of Licenses.

0
votes

Please visit https://discuss.circleci.com/t/licences-for-android-build-tools-not-accepted/17285/18

dependencies:

override:

echo y | android update sdk --no-ui --all --filter build-tools-26.0.2,android-26

instead of my original:

dependencies:

override:

echo y | android update sdk --no-ui --all --filter build-tools-26.0.2
-2
votes

Install the latest Android Studio and accept the license agreement.

https://developer.android.com/studio/index.html