【问题标题】:Could not find method implementation() for arguments找不到参数的方法 implementation()
【发布时间】:2018-05-24 10:48:40
【问题描述】:

我尝试运行我的应用程序,但 gradle 不想编写它。

你能告诉我该怎么做吗?

错误:(36, 0) 无法在 org.gradle.api.internal.artifacts.dsl 类型的对象上找到参数 [com.google.firebase:firebase-appindexing:11.6.2] 的方法 implementation()。 dependencies.DefaultDependencyHandler。

我的应用 build.gradle 文件

 minSdkVersion 14
        targetSdkVersion 22
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            signingConfig signingConfigs.config
        }
    }
    lintOptions {
        disable 'MissingTranslation'
    }
    productFlavors {
    }
}
dependencies {
    implementation 'com.google.firebase:firebase-appindexing:11.6.2'
    compile project(':AndEngine')
    compile files('libs/gson-2.8.0.jar')
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.google.firebase:firebase-core:10.2.4'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.android.gms:play-services-ads:10.2.4'
    compile 'com.google.firebase:firebase-ads:10.2.4'
    compile 'com.google.firebase:firebase-crash:10.2.4'

} 

【问题讨论】:

  • 必须使用插件 3.x.x 才能使用实现 DSL
  • @Gabriele Mariotti 谢谢,我不小心

标签: java android android-gradle-plugin build.gradle andengine


【解决方案1】:

替换

implementation 'com.google.firebase:firebase-appindexing:11.6.2'

compile 'com.google.firebase:firebase-appindexing:11.6.2'

您需要更新您的 gradle 版本才能使用implementation。 您可以在项目 build.gradle 中更新您的 buildscript 块

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}

compile 已被弃用,未来的 gradle 版本将不再支持它。

所以要让您的项目编译,只需按照我的建议更改该行,但考虑更新您的 gradle 版本并为所有依赖项使用 implementation

更新

您应该对 Firebase 依赖项的所有模块使用相同的版本。

因此您可能需要以这种方式更新您的应用 build.gradle

dependencies {
    compile 'com.google.firebase:firebase-appindexing:11.6.2'
    compile project(':AndEngine')
    compile files('libs/gson-2.8.0.jar')
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.google.firebase:firebase-core:11.6.2'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.android.gms:play-services-ads:11.6.2'
    compile 'com.google.firebase:firebase-ads:11.6.2'
    compile 'com.google.firebase:firebase-crash:11.6.2'
} 

或者你可能有新的构建错误。

还有

compile 'com.android.support:support-v4:22.2.1'

不是最新版本,可能会带来新问题。

但我建议一步一步进行:)

更新 2

如果你以这种方式声明 gson 的依赖项

compile 'com.google.code.gson:gson:2.8.0'

你不需要

compile files('libs/gson-2.8.0.jar')

这是多余的,而且你可以释放你的 libs 文件夹中的一个无用的 jar 文件

【讨论】:

  • 感谢您的回答。你是部分正确的。设置 gradle 有时可能需要很长时间。
  • 我觉得这个答案有点令人困惑。应该更改哪些 build.gradle 文件?更新部分关于这些信息不是很清楚。
  • @Zerok,我已经更新了答案。所有更新部分都引用了 app build.gradle 文件。您实际声明依赖项的地方。
猜你喜欢
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 2021-01-08
  • 2019-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-16
相关资源
最近更新 更多