【问题标题】:Flutter app failed to build due to Google firestore由于 Google Firestore,Flutter 应用程序无法构建
【发布时间】:2021-06-25 22:36:53
【问题描述】:

我是 Flutter 的新手,学习过许多不同的在线教程,但我已经被同一个问题(错误)困住了好几个星期。每次将 Flutter 连接到 firebase_auth 和 cloud_firestore 时都会出现此错误

注意:C:\Users\HP USER\AppData\Local\Pub\Cache\hosted\pub.flutter-io.cn\cloud_firestore-1.0.3\android\src\main\java\io\flutter\plugins\firebase\firestore\FlutterFirebaseFirestorePlugin.java 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。 注意:C:\Users\HP USER\AppData\Local\Pub\Cache\hosted\pub.flutter io.cn\cloud_firestore-1.0.3\android\src\main\java\io\flutter\plugins\firebase\firestore \streamhandler\TransactionStreamHandler.java 使用未经检查或不安全的操作 注意:使用 -Xlint 重新编译:详细信息未选中。 注意:C:\Users\HP USER\AppData\Local\Pub\Cache\hosted\pub.flutter-io.cn\firebase_core-1.0.2\android\src\main\java\io\flutter\plugins\firebase\ core\FlutterFirebaseCorePlugin.java 使用或覆盖已弃用的 API。
注意:使用 -Xlint:deprecation 重新编译以获取详细信息。 注意:C:\Users\HP USER\AppData\Local\Pub\Cache\hosted\pub.flutter-io.cn\firebase_auth-1.0.1\android\src\main\java\io\flutter\plugins\firebase\ auth\FlutterFirebaseAuthPlugin.java 使用或覆盖已弃用的 API。
注意:使用 -Xlint 重新编译:详细信息弃用。

我的 pubspec.yaml 看起来像这样:

名称:pakaipa_for_real 描述:一个新的 Flutter 项目。发布到: "none" # 如果您想发布到 pub.dev,请删除此行

版本:1.0.0+1

环境:
sdk: ">=2.7.0

依赖关系:
扑: sdk:颤动

firebase_core:“^1.0.2”
firebase_auth:“^1.0.1”
cloud_firestore: "^1.0.3"

dev_dependencies:
颤振测试: sdk:颤动

颤动:
使用材料设计:是的

我的 app/build.gradle 看起来像:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with 
flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID 
(https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.pakaipa_for_real"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    
    }

    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 '../..'
}

dependencies {
    implementation 'com.google.firebase:firebase-analytics'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

我的 android/build.gradle 看起来像:

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
    google()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath 'com.google.gms:google-services:4.3.5'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
} 
enter code here

提前感谢您的帮助!

【问题讨论】:

  • 你试过运行 pub upgrade 然后flutter clean 吗?
  • 是的,我试过了,但仍然遇到同样的错误

标签: firebase flutter google-cloud-firestore firebase-authentication flutter-dependencies


【解决方案1】:

在 app/build.gradle 依赖中,添加:

implementation platform('com.google.firebase:firebase-bom:26.4.0')
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-auth'

【讨论】:

    【解决方案2】:

    您需要从 app/build.gradle

    中的依赖项中删除 implementation 'com.google.firebase:firebase-analytics'

    您应该使用 pubspec.yaml 添加任何 firebase 功能依赖项,如果您需要在项目中进行分析,请在此处了解更多信息:https://pub.dev/packages/firebase_analytics

    关于必须添加 firebase 到 Flutter 应用:https://firebase.google.com/docs/flutter/setup?platform=android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 2021-04-09
      • 2020-12-27
      • 1970-01-01
      • 2020-01-09
      相关资源
      最近更新 更多