35

I just migrated gradle from 3.0.1 to 4.4. Now Android Studio showing gradle build failed showing below errors.

Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.android.tools.build:gradle:4.4. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/4.4/gradle-4.4.pom https://jcenter.bintray.com/com/android/tools/build/gradle/4.4/gradle-4.4.jar https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.4/gradle-4.4.pom https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.4/gradle-4.4.jar

Project level build.gradle file is following below

 buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        //classpath 'com.android.tools.build:gradle:3.0.1'
        //replaced by 4.4 below
        classpath 'com.android.tools.build:gradle:4.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        mavenCentral()
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Project structure is shown below.

Project Structure and gradle setting

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Kisan Thapa
  • 527
  • 1
  • 4
  • 15

2 Answers2

56

You mixed up with plugin version and distributionUrl. Plugin version should be classpath 'com.android.tools.build:gradle:3.0.1' or com.android.tools.build:gradle:3.1.0. Read Android Plugin for Gradle Release Notes.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

And distributionUrl to GradleWrapper.

distributionUrl = https\://services.gradle.org/distributions/gradle-4.4-all.zip

Currently latest Version 3 gradle plugin available on android for which you have to use classpath 'com.android.tools.build:gradle:3.1.0'.
To be up to date see Configure Your Build.

Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
ADM
  • 20,406
  • 11
  • 52
  • 83
  • And then when you change the gradle plugin to 3.1.0, if you see "Could not find org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.0" and "Required by: project :app > com.android.tools.build:gradle:3.1.0 > com.android.tools.build:gradle-core:3.1.0", check out https://stackoverflow.com/questions/49534872/after-update-to-android-studio-3-1-im-facing-this-erorr-could-not-find-org-jetb for some ideas what to do. – auspicious99 Jul 18 '18 at 13:04
  • Check the http address for the distributionUrl in a browser (leaving off the zip file name at the end). Your distributionUrl is in {project folder}\gradle\wrapper\gradle-wrapper.propterties – Graham Laight Feb 27 '19 at 14:55
  • The latest plugin version is now at [`4.1.0`](https://developer.android.com/studio/releases/gradle-plugin#4-1-0) instead of `3.1.x` and the `distributionUrl` should be at [`6.8.x`](https://gradle.org/releases/). – Brian Li Mar 05 '21 at 06:51
  • @BrianLi did you get this error too.. I updated my android studio and I have been stuck with "Cause: unable to find valid certification path to requested target" error since yesterday – lordvidex Mar 05 '21 at 15:50
  • I haven't had that issue yet, will let you know if I come across it – Brian Li Mar 07 '21 at 03:19
6

Guess you mixed up Gradle and Android Gradle Plugin regarding their versions?

The latest Android Gradle Plugin is v4.0.0 as of April 2020, which maps to Gradle v6.1.1.

Wei WANG
  • 1,748
  • 19
  • 23