最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Error adding firebase to flutter project in vs code - Stack Overflow

programmeradmin2浏览0评论

i am trying to add firebase to my project but each time this error show up:

[{
    "resource": "/c:/Users/User/StudioProjects/gp_femuna/android/app/build.gradle.kts",
    "owner": "_generated_diagnostic_collection_name_#5",
    "code": "0",
    "severity": 8,
    "message": "The supplied phased action failed with an exception.\r\nA problem occurred configuring root project 'android'.\r\nBuild file 'C:\\Users\\User\\StudioProjects\\gp_femuna\\android\\build.gradle.kts' line: 1\r\nError resolving plugin [id: 'com.google.gms.google-services', version: '4.4.2', apply: false]\r\nThe request for this plugin could not be satisfied because the plugin is already on the classpath with a different version (4.3.15).",
    "source": "Java",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}]

this is the app/build.gradle.kts:

    plugins {
    id("com.android.application")
    id("kotlin-android")
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id("dev.flutter.flutter-gradle-plugin")
    id("com.google.gms.google-services")
}

dependencies {
  // Import the Firebase BoM
  implementation(platform("com.google.firebase:firebase-bom:33.10.0"))


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation("com.google.firebase:firebase-analytics")


  // Add the dependencies for any other desired Firebase products
  // 
}

android {
    namespace = "com.example.gp_femuna"
    compileSdk = flutterpileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17.toString()
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (.html).
        applicationId = "com.example.gp_femuna"
        // You can update the following values to match your application needs.
        // For more information, see: /to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so flutter run --release works.
            signingConfig = signingConfigs.getByName("debug")
        }
    }
}

flutter {
    source = "../.."
}

and this is build.gradle.kts root level

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

plugins {
  // ...

  // Add the dependency for the Google services Gradle plugin
  id("com.google.gms.google-services") version "4.4.2" apply false

}

val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)

subprojects {
    val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
    project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register<Delete>("clean") {
    delete(rootProject.layout.buildDirectory)
}

i am trying to add firebase to my project but each time this error show up:

[{
    "resource": "/c:/Users/User/StudioProjects/gp_femuna/android/app/build.gradle.kts",
    "owner": "_generated_diagnostic_collection_name_#5",
    "code": "0",
    "severity": 8,
    "message": "The supplied phased action failed with an exception.\r\nA problem occurred configuring root project 'android'.\r\nBuild file 'C:\\Users\\User\\StudioProjects\\gp_femuna\\android\\build.gradle.kts' line: 1\r\nError resolving plugin [id: 'com.google.gms.google-services', version: '4.4.2', apply: false]\r\nThe request for this plugin could not be satisfied because the plugin is already on the classpath with a different version (4.3.15).",
    "source": "Java",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 1
}]

this is the app/build.gradle.kts:

    plugins {
    id("com.android.application")
    id("kotlin-android")
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id("dev.flutter.flutter-gradle-plugin")
    id("com.google.gms.google-services")
}

dependencies {
  // Import the Firebase BoM
  implementation(platform("com.google.firebase:firebase-bom:33.10.0"))


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation("com.google.firebase:firebase-analytics")


  // Add the dependencies for any other desired Firebase products
  // https://firebase.google/docs/android/setup#available-libraries
}

android {
    namespace = "com.example.gp_femuna"
    compileSdk = flutterpileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17.toString()
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android/studio/build/application-id.html).
        applicationId = "com.example.gp_femuna"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so flutter run --release works.
            signingConfig = signingConfigs.getByName("debug")
        }
    }
}

flutter {
    source = "../.."
}

and this is build.gradle.kts root level

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

plugins {
  // ...

  // Add the dependency for the Google services Gradle plugin
  id("com.google.gms.google-services") version "4.4.2" apply false

}

val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)

subprojects {
    val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
    project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register<Delete>("clean") {
    delete(rootProject.layout.buildDirectory)
}
Share Improve this question edited Mar 15 at 12:41 Doug Stevenson 318k36 gold badges456 silver badges473 bronze badges Recognized by Google Cloud Collective asked Mar 15 at 8:30 Heba StayHeba Stay 92 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Your Error says

plugin [id: 'com.google.gms.google-services', version: '4.4.2', apply: false]\r\nThe request for this plugin could not be satisfied because the plugin is already on the classpath with a different version (4.3.15).

This conflict arises because the com.google.gms.google-services plugin is declared with different versions in your project's Gradle files. One part of your build configuration specifies version 4.4.2, while another part includes version 4.3.15. Gradle requires consistent plugin versions to function correctly.

Try these :

1.Ensure that the com.google.gms.google-services plugin is declared only once with a consistent version. In your project-level build.gradle.kts, you might have:

plugins {
    id("com.android.application") version "7.0.0" apply false
    id("com.google.gms.google-services") version "4.4.2" apply false
    // Other plugins...
}

Verify that this version matches the one used in your app/build.gradle.kts.

2. In your app-level build.gradle.kts, ensure that you apply the plugin without specifying the version:

plugins {
    id("com.android.application")
    id("kotlin-android")
    id("com.google.gms.google-services")
    // Other plugins...
}

Ensure that all instances of the com.google.gms.google-services plugin in your project use the same version. If other plugins or dependencies specify this plugin, update them to align with your chosen version.

3. Clean and rebuild


./gradlew clean
./gradlew build

To avoid errors, you can use the flutter fire to setup firebase for project. The instructions on how to use flutterfire is given here

发布评论

评论列表(0)

  1. 暂无评论