Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle failed to restore: Unable to find method 'org.gradle.api.file.ProjectLayout.directoryProperty

Tags:

android

gradle

I was loading an Android project that downloaded from Github, the project look fairly recent and nothing weird that I can find. But when I open it, it failed to build with the following error:

Unable to find method 'org.gradle.api.file.ProjectLayout.directoryProperty(Lorg/gradle/api/provider/Provider;)Lorg/gradle/api/file/DirectoryProperty;'. 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.

Other android projects that were created on my machine works fine. What can be the issue?

like image 632
Visual Sharp Avatar asked Aug 01 '20 15:08

Visual Sharp


2 Answers

The issue was that I upgraded to Android Studio v4, and seem like the download project was created using Android Studio v3. After go to

File/ Project Structure.../

And change the Android Gradle Plugin Version from 3.3.1 to 4.0.1 and now project loaded fine. Not sure why Android Studio v4 is not backward compatible with Gradle version 3. enter image description here

like image 64
Visual Sharp Avatar answered Nov 11 '22 22:11

Visual Sharp


To determine plugin version and required Gradle version, developers can refer the compatibility matrix provided in Android documentation from here.

Plugin version Required Gradle version
1.0.0 - 1.1.3 2.2.1 - 2.3
1.2.0 - 1.3.1 2.2.1 - 2.9
1.5.0 2.2.1 - 2.13
2.0.0 - 2.1.2 2.10 - 2.13
2.1.3 - 2.2.3 2.14.1 - 3.5
2.3.0+ 3.3+
like image 3
Visuddha Karunaratne Avatar answered Nov 11 '22 22:11

Visuddha Karunaratne