Updating gradle, Could not find method compile() for arguments
Asked Answered
W

3

5

I'm trying to update the gradle to version 7.0.1 on an ionic capacitor project. I keep getting this error

Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method compile() for arguments [{name=barcodescanner-release-2.1.5, ext=aar}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

I searched a lot to fix this issue but all possible fixes say that I need to change the "compile" method "implementation" in "app/build.grade", but actually the file doesn't contain the "compile" method!

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "****"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 10
        versionName "1.8"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        aaptOptions {
             // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
             // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    flatDir{
        dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')
}

apply from: 'capacitor.build.gradle'

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}

Wachtel answered 8/11, 2022 at 21:15 Comment(1)
#23796904 Hope it helps! – Pleonasm
W
17

Ok, the problem is solved. The problem was that the barcodescanner plugin was configured to use the compile method, and by changing it to implementation the problem is solved.

To change the configuration method of any plugin go to File > Project Structure > Dependencies, then in the details section, you will find "Configuration".

Wachtel answered 9/11, 2022 at 21:34 Comment(1)
In my case it was hard to find the place to change "compile" to "implementation". File path: node_modules/phonegap-plugin-barcodescanner/src/android/barcodescanner.gradle Finally it looks like this: dependencies{ implementation(name:'barcodescanner-release-2.1.5', ext:'aar') } – Suzisuzie
O
9

For those of you like me who are having this issue with a Cordova project, manage your projects with the Cordova CLI and don't use Android Studio, you just need to edit the platforms/android/phonegap-plugin-barcodescanner/prod-barcodescanner.gradle file and change:

dependencies {
    compile(name:'barcodescanner-release-2.1.5', ext:'aar')
}

to:

dependencies {
    implementation(name:'barcodescanner-release-2.1.5', ext:'aar')
}
Ojeda answered 12/2, 2023 at 20:31 Comment(1)
Perfect! πŸ˜ƒβ€Š Great example, it helps a lot. Thanks! – Tide
B
0

I fixed the problem installing one of the scanner's forks:

cordova < 7: cordova plugin add @starley/barcodescanner-sdk31

cordova >= 7: cordova plugin add barcodescanner-ec

Blanding answered 26/6, 2024 at 15:19 Comment(0)

© 2022 - 2025 β€” McMap. All rights reserved.