java - 找不到参数的方法实现() [DefaultExternalModuleDependency{group ='com.google.firebase' ,

标签 java android android-gradle-plugin

我在发帖之前做了一些搜索。 我创建了一个新项目,内容如下:

来自:(构建gradle项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}

致:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.4.2' apply false
    id 'com.android.library' version '7.4.2' apply false
}
dependencies {
    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:31.3.0')


    // TODO: Add the dependencies for Firebase products you want to use
    // When using the BoM, don't specify versions in Firebase dependencies
    // https://firebase.google.com/docs/android/setup#available-libraries
}

所以我得到了这个错误:

Could not find method implementation() for arguments [DefaultExternalModuleDependency{group='com.google.firebase', name='firebase-bom', version='31.3.0', configuration='default'}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

这是 gradle 应用

plugins {
    id 'com.android.application'
}

android {
    namespace 'com.example.delivery1'
    compileSdk 33

    defaultConfig {
        applicationId "com.example.delivery1"
        minSdk 25
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
    implementation 'androidx.navigation:navigation-fragment:2.5.3'
    implementation 'androidx.navigation:navigation-ui:2.5.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
    classpath 'com.google.gms:google-services:4.3.15'
}

最佳答案

您在dependency { ... } 中使用的实现实际上是一个配置。 此配置需要通过您应用的某些插件添加,因为默认情况下 Gradle 构建中不存在任何配置。 像 javakotlin("jvm")com.android.application 这样的语言插件(或它们传递应用的插件),添加这样的然后您可以添加依赖项的配置。

在您展示的根项目构建脚本中,您没有应用任何插件,因此也没有可以添加依赖项的配置,因此您会收到 gradle 的投诉,实现不存在。

您可能想将此行添加到您的应用程序级构建脚本中。

关于java - 找不到参数的方法实现() [DefaultExternalModuleDependency{group ='com.google.firebase' ,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75988906/

相关文章:

Android Studio-构建失败

java - 设置 while 语句来打印方法?

java - 无法在我的可执行 jar 中包含外部 jar

java - 如何以编程方式更改选择器内形状的颜色?

c# - Xamarin.Forms如何根据条件绑定(bind)背景颜色

android - Google Pay 无法与 Braintree SDK 配合使用

android - 无法解析 : junit:junit:4. 12

java - Spring实例化Bean错误

java - 启动只有我的客户端可以连接的 IRC 服务器

java - 向 Android Studio 添加外部库时出现非法参数异常