39

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

Amit Singh
  • 1,790
  • 3
  • 17
  • 27
  • refer http://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences – sasikumar Nov 03 '16 at 03:36
  • 1
    Possible duplicate of [Can't accept license agreement Android SDK Platform 24](http://stackoverflow.com/questions/40383323/cant-accept-license-agreement-android-sdk-platform-24) – Divyesh Savaliya Nov 03 '16 at 04:59
  • Solution here: http://stackoverflow.com/questions/40383323/cant-accept-license-agreement-android-sdk-platform-24/41279429#41279429 – John Dec 22 '16 at 09:13

18 Answers18

47

Install the license:

mkdir "%ANDROID_HOME%\licenses"

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

Community
  • 1
  • 1
Peter.Wang
  • 2,051
  • 1
  • 19
  • 13
  • 1
    I have no %ANDROID_HOME% environment variable. Tried using %ADT_HOME% instead, no luck. I'm on Win7. Any thoughts? – mpsyp Jan 10 '17 at 21:12
  • @mpsyp ANDROID_HOME is your android SDK location. If you don't have it in the windows environment variable, create one and pointing to the folder contains the android sdk package. – Peter.Wang Feb 11 '17 at 12:53
  • How to do it on windows 7 ? – wahmal Apr 25 '17 at 08:26
  • This is a good answer. Also please make sure that your android-sdk folder has READ/WRITE permissions given. – Abhay Shiro Jun 30 '17 at 05:13
  • 2
    worked for me on Linux. If you don't want to use only command line, make a folder called licenses in Android/sdk/, make the file android-sdk-license, copy 8933bad161af4178b1185d1a37fbf41ea5269c55. Thanks Pete! – spencer Jul 05 '17 at 01:52
19

In Command Prompt, go to ANDROID_HOME\tools\bin

Then run the command, sdkmanager --licenses

Accept the licenses you want when it is prompted.

Harikrishnan K.N.
  • 4,560
  • 2
  • 17
  • 28
18

Install Platform 24 (Android 7) solved this problem

Amit Singh
  • 1,790
  • 3
  • 17
  • 27
  • Worked for Cordova CLI 6.4.0 / Windows 8.1 :) Thanks! – Eric Gopak Dec 11 '16 at 17:53
  • 2
    installed 24 with SDK manager, no luck. I've never had this problem before, just started after uninstalling and reinstalling Ionic+Cordova, etc. Builds worked fine before. Why is it showing up now? – mpsyp Jan 10 '17 at 21:14
  • @mpsyp After Peter Wang's solution when I started the build again I saw android 25 was installed and build succeeded. So maybe installing android 25 may solve the issue. – Koushik Sarkar Jan 26 '17 at 16:58
  • This does not always work. The solution by Peter Wang bypasses the possibility of error while the license is still valid. – Travis Don Kindred Apr 05 '17 at 20:10
12

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

Nikola
  • 981
  • 1
  • 10
  • 20
7
  1. Go to C:\Users\<UserName>\AppData\Local\Android\Sdk\tools\bin
  2. Run command ./sdkmanager.bat --licenses
  3. accept license

Worked for me

Roger Garcia
  • 327
  • 2
  • 12
Niyas Ibrahim
  • 111
  • 1
  • 4
  • At step 1 you forgot "AppData" between username and local (so the path is `C:\Users\\AppData\Local\Android\Sdk\tools\bin`), and at step 2, the command I had to execute was `./sdkmanager.bat --licenses`. With that, I was able to build for android without issues. Thanks for your help. If you accept the edit I send, I think this should be the accepted answer. It focus exactly on where the problem was and solves it. – Roger Garcia Jun 14 '18 at 16:52
2

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

Community
  • 1
  • 1
abumalick
  • 2,136
  • 23
  • 27
2

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"
xlm
  • 6,854
  • 14
  • 53
  • 55
  • In my case it was only enough to add ANDROID_HOME environment variable, as the license was already there. – vivanov Oct 16 '17 at 17:31
2

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

Community
  • 1
  • 1
Daniel
  • 7,684
  • 7
  • 52
  • 76
1

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

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.

bzret
  • 19
  • 5
0

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

Jeevan
  • 518
  • 3
  • 8
0

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

Buggy man
  • 61
  • 1
  • 2
0

I've solved my problem with this.

mkdir "%ANDROID_HOME%\licenses"

echo |set /p="8933bad161af4178b1185d1a37fbf41ea5269c55" > "%ANDROID_HOME%\licenses\android-sdk-license"
ErmIg
  • 3,980
  • 1
  • 27
  • 40
Sam
  • 1
0

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.

jsina
  • 4,433
  • 1
  • 30
  • 28
0

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

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.

Rahul
  • 21
  • 4
0

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
colm.anseo
  • 19,337
  • 4
  • 43
  • 52
-2

Install the latest Android Studio and accept the license agreement.

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

Matt
  • 33,328
  • 25
  • 83
  • 97