I am posting the question after having a look at all similar questions and answers.
Here are the questions I studied.
Could not find method compile() for arguments Gradle
Gradle Could not find method compile() for arguments
Maybe, you might wonder that it's a duplicate question but in my case, it's not. Let's see how it is. First, here is the code snippet that the error comes from:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.facebook.react:react-native:+"
}
This code is from the file: node_modules/react-native-geocoder/android/build.gradle
Now let me show you what error shows up.
FAILURE: Build failed with an exception.
* Where:
Build file '/Project-root/node_modules/react-native-geocoder/android/build.gradle' line: 19
* What went wrong:
A problem occurred evaluating project ':react-native-geocoder'.
> Could not find method compile() for arguments [directory 'libs'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 26s
All answers say that you need to replace compile()
method with implementation()
method because compile()
method is deprecated from gradle 7.0
and currently I am using gradle 7.4
.
But editing files inside node_modules
folder is not a good idea as everybody knows.
And it's react-native
project and the package in issue is react-native-geocoder
.
I browsed react-native-geocoder repo
but it's achieved by its owner and read-only now. So I cannot submit PR to the repo.
https://github.com/devfd/react-native-geocoder
I would like to discuss about any wiser answer. What is a fundamental answer to fix this issue? Thank you!
react-native-geocoder compile issue:
You can fix this issue by replacing compile
with implementation
in node_modules/react-native-geocoder/android/build.gradle.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.facebook.react:react-native:+"
}
changed to
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.facebook.react:react-native:+"
}
Compile method has been deprecated from gradle 4.0 and completely removed from gradle 7.0