Licenses not accepted when running on device

Hi, i installed Ionic 4 to work in an app. Everything was allright using “serve” command but when i tried to use “ionic cordova run android -l” command the problems started.
I’ve been struggling with sdk issues for the last 4 hours (#crazysaturdays :slight_smile:). I reached a dead end, apperently ionic cli is not accepting the sdkmanager licenses:
I did every solution that are recommended in similar posts in the forum but the problem persists.

Here my ionic info

Ionic:

   ionic (Ionic CLI)          : 4.2.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.12
   @angular-devkit/core       : 0.7.5
   @angular-devkit/schematics : 0.7.5
   @angular/cli               : 6.1.5
   @ionic/ng-toolkit          : 1.1.0
   @ionic/schematics-angular  : 1.0.7

Cordova:

   cordova (Cordova CLI) : 8.1.1 (cordova-lib@8.1.0)
   Cordova Platforms     : android 7.1.1
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 5 other plugins)

System:

   NodeJS : v8.12.0 (/usr/bin/node)
   npm    : 6.4.1
   OS     : Linux 4.15

And the output when i run “ionic cordova run android -l”:

> ng run app:ionic-cordova-serve --host=0.0.0.0 --port=8100 --platform=android

[INFO] Development server running!
       
       Local: http://localhost:8100
       External: http://192.168.1.33:8100
       
       Use Ctrl+C to quit this process

> cordova run android
[cordova]  Android Studio project detected
[cordova]  ANDROID_HOME=/usr/lib/android-sdk
[cordova]  JAVA_HOME=/usr/lib/jvm/java-8-oracle
[cordova]  studio
[cordova]  Subproject Path: CordovaLib
[cordova]  Subproject Path: app
[cordova]  publishNonDefault is deprecated and has no effect anymore. All variants are now published.
[cordova]  WARNING: The specified Android SDK Build Tools version (24.0.0) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1.
[cordova]  Android SDK Build Tools 26.0.2 will be used.
[cordova]  To suppress this warning, remove "buildToolsVersion '24.0.0'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
[cordova]  Observed package id 'build-tools;24.0.0' in inconsistent location '/usr/lib/android-sdk/build-tools/debian' (Expected '/usr/lib/android-sdk/build-tools/24.0.0')
[cordova]  Already observed package id 'build-tools;24.0.0' in '/usr/lib/android-sdk/build-tools/24.0.0'. Skipping duplicate at '/usr/lib/android-sdk/build-tools/debian'
[cordova]  Checking the license for package Android SDK Build-Tools 26.0.2 in /usr/lib/android-sdk/licenses
[cordova]  Warning: License for package Android SDK Build-Tools 26.0.2 not accepted.
[cordova]  Checking the license for package Android SDK Platform 27 in /usr/lib/android-sdk/licenses
[cordova]  Warning: License for package Android SDK Platform 27 not accepted.
[cordova]  
[cordova]  FAILURE: Build failed with an exception.
[cordova]  
[cordova]  * What went wrong:
[cordova]  A problem occurred configuring project ':CordovaLib'.
[cordova]  > You have not accepted the license agreements of the following SDK components:
[cordova]    [Android SDK Platform 27, Android SDK Build-Tools 26.0.2].
[cordova]    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.
[cordova]    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
[cordova]  
[cordova]  * Try:
[cordova]  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[cordova]  
[cordova]  * Get more help at https://help.gradle.org
[cordova]  
[cordova]  BUILD FAILED in 0s
[cordova]  /home/pablo/Documentos/app/Tizem/platforms/android/gradlew: Command failed with exit code 1 Error output:
[cordova]  FAILURE: Build failed with an exception.
[cordova]  
[cordova]  * What went wrong:
[cordova]  A problem occurred configuring project ':CordovaLib'.
[cordova]  > You have not accepted the license agreements of the following SDK components:
[cordova]    [Android SDK Platform 27, Android SDK Build-Tools 26.0.2].
[cordova]    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.
[cordova]    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
[cordova]  
[cordova]  * Try:
[cordova]  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
[cordova]  
[cordova]  * Get more help at https://help.gradle.org
[cordova]  
[cordova]  BUILD FAILED in 0s
[ERROR] An error occurred while running subprocess cordova.
        
        cordova run android exited with exit code 1.
        
        Re-running this command with the --verbose flag may provide more information.

yeah, i know, “god is not here” right?
Any clues?
thanks!

If you don’t get any better answers, I’m a big fan of sdkmanager. Here’s a snippet of how I install this part of the toolchain in a Docker image I use for building Ionic apps:

RUN curl -o android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN apt-get update && apt-get install -y \
    unzip \
    openjdk-8-jdk-headless \
    gradle \
    libxml2-utils \
    lsb-release \
    software-properties-common \
    apt-transport-https

RUN mkdir /opt/android
RUN unzip -d /opt/android android-sdk.zip
RUN echo "y" | /opt/android/tools/bin/sdkmanager --install "build-tools;28.0.3"
ENV ANDROID_HOME /opt/android

You should be able to more or less run each of these things (it would require root, but by changing the paths to somewhere under your home directory, you could avoid that).

Yesterday i tried but the problem is still there.
Don’t worry i format the pc and install windows. Now is working fine :slight_smile:

The easiest way I solve this is, go the directory of the android then > sdk > licenses delete the the license inside then reinstall the sdk. follow

  1. On a machine with Android Studio installed, click Tools > Android > SDK Manager . At the top of the window, note the Android SDK Location.
  2. Navigate to that directory and locate the licenses/ directory inside it. (If you do not see a licenses/ directory, return to Android Studio and update your SDK tools, making sure to accept the license agreements. When you return to the Android SDK home directory, you should now see the directory.)
  3. Copy the entire licenses/ directory and paste it into the Android SDK home directory on the machine where you wish to build your projects.