Android build failed (Minimum supported Gradle version is 4.1. Current version is 3.4.1.)

Hello,
i just started trying packaging with ionic pro.

But the first build failed:

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘/usr/src/app/platforms/android/build.gradle’ line: 20

  • What went wrong:
    A problem occurred evaluating root project ‘android’.

Failed to apply plugin [id ‘com.android.application’]
Minimum supported Gradle version is 4.1. Current version is 3.4.1. If using the gradle wrapper, try editing the distributionUrl in /usr/src/app/gradle/wrapper/gradle-wrapper.properties to gradle-4.1-all.zip

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

BUILD FAILED

Total time: 33.044 secs
Error: /usr/src/app/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

  • Where:
    Build file ‘/usr/src/app/platforms/android/build.gradle’ line: 20

  • What went wrong:
    A problem occurred evaluating root project ‘android’.

Failed to apply plugin [id ‘com.android.application’]
Minimum supported Gradle version is 4.1. Current version is 3.4.1. If using the gradle wrapper, try editing the distributionUrl in /usr/src/app/gradle/wrapper/gradle-wrapper.properties to gradle-4.1-all.zip

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    Failed to build apk check logs above for errors.
    Running after script…
    $ clean-up
    Cleaning up files…
    Successful clean up
    ERROR: Job failed: exit status 1

Local android building works fine.

Regards
nowrap

What is your ionic info output?

#info info

cli packages: (C:\Users\nowrap\AppData\Roaming\npm\node_modules)

@ionic/cli-utils  : 1.18.0
ionic (Ionic CLI) : 3.18.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.2
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v8.6.0
npm  : 5.5.1
OS   : Windows 10

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

I would try to add the Android platform locally and see if that fixes it.

If not, this looks a bit like something the Ionic people should look at via their support channels as there is not much to go on:
Support

1 Like

hmmm, platforms are installed:

cordova platform ls
Installed platforms:
android 6.4.0
browser 5.0.1
ios 4.5.3

local android builds are working:
ionic cordova run android -l -c

Hmm, then I would try to find out why ionic info isn’t listing them… suspicious. (But can very well be unrelated to the original problem)

i removed them and readded them.
now they are listed:

local packages:

@ionic/app-scripts : 3.1.2
Cordova Platforms  : android 6.3.0 ios 4.5.3
Ionic Framework    : ionic-angular 3.9.2

ionic pro can build the ios package

the android package still fails. but now the error is different:

Checking the license for package Android SDK Platform 26 in /opt/android-sdk/licenses
Warning: License for package Android SDK Platform 26 not accepted.

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 26].
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 Exporting licenses - Android Studio Project Site

Next I would do:
https://cordova.apache.org/announcements/2017/11/09/android-release.html

done, build is running:

ionic cordova platform rm android
ionic cordova platform add android@6.4.0

// edit
build failed again with the initial posted error

So although you are on the current cordova-android now you are getting the Gradle error again? Then I would say again that this is something support should look at: http://ionicframework.com/support#support

That worked for me. I had upgraded Gradle from Android Dev environment and had the build issue.
removing the android platform manually, then re-adding fixed it.