更新 gradle,找不到参数的方法compile()

Isl*_*med 4 android gradle ionic-framework

我正在尝试将离子电容器项目的 gradle 更新到版本 7.0.1。我不断收到此错误

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.
Run Code Online (Sandbox Code Playgroud)

我搜索了很多来解决这个问题,但所有可能的修复都表明我需要更改“app/build.grade”中的“编译”方法“实现”,但实际上该文件不包含“编译”方法!

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")
}

Run Code Online (Sandbox Code Playgroud)

Isl*_*med 15

好的,问题解决了。问题是条形码扫描仪插件被配置为使用编译方法,通过将其更改为实现,问题得到解决。

要更改任何插件的配置方法,请转到“文件”>“项目结构”>“依赖项”,然后在详细信息部分中,您将找到“配置”。


Mik*_*lor 8

对于像我这样在 Cordova 项目中遇到此问题的人,请使用 Cordova CLI 管理您的项目,而不使用 Android Studio,您只需要编辑platforms/android/phonegap-plugin-barcodescanner/prod-barcodescanner .gradle 文件并更改:

dependencies {
    compile(name:'barcodescanner-release-2.1.5', ext:'aar')
}
Run Code Online (Sandbox Code Playgroud)

到:

dependencies {
    implementation(name:'barcodescanner-release-2.1.5', ext:'aar')
}
Run Code Online (Sandbox Code Playgroud)