Gradle build failing after update to 3.0

烂漫一生 提交于 2019-11-27 18:04:47

Upgrade your gradle build tools to the latest version.

One easy way to do this is to add the latest version of the build tools as a dependency in your build.gradle file, for example:

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0-beta1'
}

You can then run gradle tasks and gradle will download everything you need.

After Android Studio 2.2 stable released on Sep 19 2016 , the latest version of the build tools is 2.2.0 . So you can fix it by :

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
}

As Android Studio 2.4 stable is not ready to release yet (May 4 2017), the latest stable version of build tools is 2.3.1 .

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
}

If you update this build tools version to 2.3.* , you should also update gradle wrapper version to 3.3 in /yourProjectRoot/gradle/wrapper/gradle-wrapper.properties file. (i know it is not matching question Gradle build failing after update to 3.0, but i strongly suggest you to use latest build tool as google recommended)

BTW: version 2.3.1 of build tool is only exist on jCenter, not MavenCentral, so if you run into error below when run gradlew command line in terminal

Could not find com.android.tools.build:gradle:2.3.1.
 Searched in the following locations:
     https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.pom
     https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.jar

just replace mavenCentral() with jcenter() like

 repositories {
    jcenter()
    //mavenCentral()
}

For latest update of Android Studio 3.0

In gradle-wrapper.properties(File Name) change URL of distributionUrl to the following:

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

If you use gradle plugin 2.1.3, It's simple to solve:

update your gradle plugin to version 2.2.0-beta1

Notes: this is a beta version, maybe you can get any other issues.

https://discuss.gradle.org/t/classcastexception-in-gradle-nightly-3-0-20160609/17979

Happy coding :)

Okay I got it working. For anyone facing the same problem the way it worked for me is as follows:

  1. Go to your external .gradle folder (for me it was C:\Users\drilon.gradle). Inside caches and daemon folder delete all the version folder (they look like this "2.14.1", or "3.0"). Also go to wrapper -> dists -> delete everything there.
  2. Inside your project root (for me it was C:\Users\drilon\AndroidStudioProjects\PorjectName) go to the .gradle folder and delete everything there.
  3. Rebuild the project

EDIT:
Turns out this solution was setting the gradle version back to 2.14.1. ending0421's solution is the working one.

if your gradle version is: 3.0.1 then use below code in your gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

if 3.1.2 then use below code in your gradle-wrapper.properties distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

satyawan hajare

For latest update of Android Studio 3.3.1 below code work.

1) gradle-wrapper.properties add below line.

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

2)build.gradle in project level add below classpath

 dependencies
    {
        classpath 'com.android.tools.build:gradle:3.1.0'

    }

Simply delete everything inside gradle folder in main project folder and Rebuild the project. It will start working.

If your gradle plugin 3.0.0 for studio version 3.0, Add this in gradle-wrapper.properties

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

simple answer try this...

goto build.gradle(PROJECT) and check the gradle version as shown below

'com.android.tools.build:gradle:2.1.3' or 3.0 or 3.1 or xx.xx

now open gradle-wrapper.properties see this line of code if gradle version is 2.x this the code below...

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

gradle-2.14.1-all.zip line of code must be same as gradle version

example:

example: mine is 2.x so... classpath 'com.android.tools.build:gradle:2.1.3' in build.gradle so

distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip in gradle-wrapper.properties.

if gradle version is 3.x then classpath 'com.android.tools.build:gradle:3.1.0' in build.gradle then

distributionUrl=https://services.gradle.org/distributions/gradle-3.14.1-all.zip in gradle-wrapper.properties.

check this it will works

satyawan hajare

if Android Studio Android Studio 3.0 below code work.

gradle-wrapper.properties add below line.

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

if Android Studio Android Studio 3.1.2 below code work.

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

if Android Studio 3.3.1 below code work.

1) gradle-wrapper.properties add below line.

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

2) build.gradle in project level add below

 dependencies { 
             classpath 'com.android.tools.build:gradle:3.1.0'
 }
    After 1 hour R&D No Solution as worked for me...

    But still i have solution follow this its work 100%

    step 1: upgrade your build.gradle(Project:<your project name>)
    Example :  classpath 'com.android.tools.build:gradle:2.1.3' // old gradle file
               classpath 'com.android.tools.build:gradle:2.3.1' // upgraded file 

                                OR
               classpath 'com.android.tools.build:gradle:3.1.0'

    Step 2 : Upgrade compileSdkVersion buildToolsVersion 
    Example : compileSdkVersion 23    buildToolsVersion "23.0.3 // old api's
              compileSdkVersion 25    buildToolsVersion "25.0.2" // upgraded api's

   Step 3:  upgrade gradle-wrapper.properties 
   Example : distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip // old or any version
            distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip // new or any version

Step 4 : finally goto build>rebuild project...

Still You face some problem commit or inbox me....

......End @Ambilpura

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!