'How to fix the error "Could not find method compile() for arguments [directory 'libs']" fundamentally?

I am posting this question after having a look at all similar questions and answers.

Here are the questions I researched.

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 different. 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 wiser answer. What is a fundamental answer to fix this issue? Thank you!



Solution 1:[1]

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

Solution 2:[2]

You can try something like this:

import future.keywords.in

violation[{"msg": msg}] {
    input.request.kind.kind == "Deployment"

    some container in input.request.object.spec.template.spec.containers
    not container.resources.limits.memory
    msg := sprintf("Container '%v/%v' does not have memory limits", [input.request.object.metadata.name, container.name])
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammad Haidar
Solution 2 Vasili Angapov