Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build Gradle Error Could not get unknown property 'compile'

i have react native porject when run android this error showed

Build file 'C:\dev\icnet_final\android\app\build.gradle' line: 213

A problem occurred evaluating project ':app'.

Could not get unknown property 'compile' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.

like image 799
Mehrad Farahnak Avatar asked Sep 03 '21 11:09

Mehrad Farahnak


People also ask

Why does Gradle 7+ fail to compile my code?

This exception is being thrown from gradle 7+ which does not recognize the property 'compile' any more as it requires the use of 'implementation' or 'api' according to the case. If the .class files are already available, configurations.runtimeClasspath should also work, as it points out to the already compiled java code.

What happened to sourceSet compileconfigurationname in Gradle?

The property SourceSet.compileConfigurationName has been deprecated for a long time and was removed in Gradle 7. The error is probably coming from one of the plugins you’re applying. Running Gradle with -s should give you a full stack trace and should help narrow down which plugin is trying to access that property.

What does Gradle task configuration compileclasspath do?

Assuming that the gradle task is trying to compile some java code, you have to replace configurations.compile with configurations.compileClasspath. It points out to the list of dependencies that the JDK requires to compile the java code.

How to find out which Gradle plugin is trying to access?

Running Gradle with -s should give you a full stack trace and should help narrow down which plugin is trying to access that property. Once you determine that, check to see if there is a newer version that is compatible with Gradle 7.


Video Answer


4 Answers

If this happens after Gradle upgrade, replace compile with implementation

like image 195
Gowtham Gowda Avatar answered Oct 21 '22 13:10

Gowtham Gowda


I got this error because I upgraded to the latest version of Gradle. I suggest not doing this yet, until React Native has been updated to work with it.

I changed my version of Gradle in android/build.gradle to the old version and the project built again. This version now works for me:

    classpath('com.android.tools.build:gradle:4.2.2')
like image 31
disconnectionist Avatar answered Oct 21 '22 13:10

disconnectionist


RN 0.64.1 For the dependence, I use

    classpath('com.android.tools.build:gradle:7.0.0')

and for the wrapper

    distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
like image 1
Alexis Defontaine Avatar answered Oct 21 '22 14:10

Alexis Defontaine


Assuming that the gradle task is trying to compile some java code, you have to replace configurations.compile with configurations.compileClasspath. It points out to the list of dependencies that the JDK requires to compile the java code.

This exception is being thrown from gradle 7+ which does not recognize the property 'compile' any more as it requires the use of 'implementation' or 'api' according to the case.

If the .class files are already available, configurations.runtimeClasspath should also work, as it points out to the already compiled java code.

like image 1
Cleber Jorge Amaral Avatar answered Oct 21 '22 12:10

Cleber Jorge Amaral