Flutter 应用程序在添加 google_sign_in 依赖项时崩溃

问题描述 投票:0回答:1

我只是想通过 firebase 在我的 flutter 应用程序(项目)中添加 google 登录功能,但每次我在 flutter 项目中添加 google_sign_in 依赖项时。该应用程序无法运行并失败并显示错误消息。但是当我删除这种依赖关系时,它就可以正常工作。我真的很想在我的应用程序中添加此功能,但每当我尝试时都无法添加此功能,即使在新项目中,我也经常发生这种情况。

错误信息-

warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':google_sign_in_android:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':google_sign_in_android:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: C:\Users\huzai\AppData\Local\Android\sdk\platforms\android-34\core-for-system-modules.jar.
         > Error while executing process C:\Program Files\Android\Android Studio\jbr\bin\jlink.exe with arguments {--module-path C:\Users\huzai\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\temp\jmod --add-modules java.base --output C:\Users\huzai\.gradle\caches\transforms-3\4a46fc89ed5f9adfe3afebf74eb8bfeb\transformed\output\jdkImage --disable-plugin system-modules}

这是我的项目配置-
安装的 Java 版本 - Java_17

颤振版本 - 3.24.4

android/app/build.gradle 文件 -

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

android {
    namespace = "com.example.letsmeetz"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.letsmeetz"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 23
        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.debug
        }
    }
}

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

android/build.gradle -

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

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

pubspec.yaml 中的依赖项 -

  cupertino_icons: ^1.0.8
  firebase_core: ^3.6.0
  cloud_firestore: ^5.4.4
  firebase_auth: ^5.3.1
  google_sign_in: ^6.2.1

我在设置与 Firebase 的连接之前和之后都进行了尝试,在这两种情况下构建都失败了。

我对 flutter 项目构建很陌生,比如配置 buildscript 等,所以如果可以的话请全面提及。我很乐意在任何事情上获得任何帮助!
如果我需要进一步提及一些事情,也请提及。

我尝试了所有的事情,并遵循了 chatGpt 建议的所有事情。
尝试清理并重建 flutter 项目,多次清除缓存 -

flutter clean

flutter pub get 

甚至安装并尝试了多个jdk 17、20、21。

android flutter dependencies build.gradle google-signin
1个回答
0
投票

您可以在此线程中找到解决方案:https://stackoverflow.com/a/79068663

  1. 将 android/settings.gradle 文件中的 com.android.application 插件更新至版本 8.3.2

  2. 在 gradle-wrapper.properties 文件中将 distributionUrl 设置为版本 8.5,一切对我来说再次正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.