Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build failing after update to 3.0

I've recently updated the gradle version of my project from 2.14.1 to 3.0. Since then the gradle build is failing every time with this error:

Error:Cause: org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

I've searched google and found some solutions like this one but nothing is working. Does anyone know how to fix it?

like image 923
Drilon Blakqori Avatar asked Aug 19 '16 08:08

Drilon Blakqori


People also ask

Why is my Gradle build failing?

If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.

How do I fix build gradle?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.


2 Answers

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() } 
like image 90
ending0421 Avatar answered Oct 16 '22 02:10

ending0421


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

like image 42
Dhaval Jardosh Avatar answered Oct 16 '22 02:10

Dhaval Jardosh