ID 为“com.android.application”的插件已在第 1 行请求

Plugin with id 'com.android.application' was already requested at line 1

提问人:Bryan Antonnio 提问时间:11/13/2023 最后编辑:Doug StevensonBryan Antonnio 更新时间:11/13/2023 访问量:23

问:

我仍然不明白为什么会这样。我什么也没做,突然我收到这个错误说

ID 为“com.android.application”的插件已在第 1 行请求

代码如下

plugins {
    id("com.android.application")
    id("com.google.gms.google-services") version "4.4.0" apply false
    id("com.android.application")
    id("com.google.gms.google-services")
}

android {
    namespace = "com.example.automaticgate"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.automaticgate"
        minSdk = 28
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = 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.10.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2")
    implementation("androidx.navigation:navigation-fragment:2.7.5")
    implementation("androidx.navigation:navigation-ui:2.7.5")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    // Import the BoM for the Firebase platform
    implementation(platform("com.google.firebase:firebase-bom:32.5.0"))

    // Add the dependency for the Realtime Database library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation("com.google.firebase:firebase-database")
}

这是错误错误显示这么多行,所以我只发布屏幕截图

我尝试以不同的名称和包创建一个新项目,但问题仍然相同。请帮忙,我可能会哭:')

Firebase Gradle Android-gradle插件

评论

0赞 Stultuske 11/13/2023
这是因为您的插件部分中有两行:id(“com.android.application”),其中一行位于第 1 行,如错误消息所述

答:

0赞 Doug Stevenson 11/13/2023 #1

您应用了两个插件两次:

plugins {
    id("com.android.application")
    id("com.google.gms.google-services") version "4.4.0" apply false
    id("com.android.application")
    id("com.google.gms.google-services")
}

只需删除重复项即可。