Flutter 应用程序未使用 cloud_firestore 插件编译
Posted
技术标签:
【中文标题】Flutter 应用程序未使用 cloud_firestore 插件编译【英文标题】:Flutter app is not compiled with cloud_firestore plugin 【发布时间】:2019-03-05 18:24:50 【问题描述】:我已经在android/app
下添加了google-service.json
。但是当我尝试构建应用程序时收到错误消息。
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':cloud_firestore:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.4.2.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Finished with error: Gradle task assembleDebug failed with exit code 1
我试过flutter clean
-> flutter packages get
但它不能解决我的问题。
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
http: ^0.11.3+17
json_annotation: ^0.2.3
cloud_firestore: ^0.8.0
app/build.gradle
dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
apply plugin: 'com.google.gms.google-services'
我没有添加implementation 'com.google.firebase:firebase-core:16.0.3'
和implementation 'com.google.firebase:firebase-database:16.0.2'
,因为我遵循codelab 指南。(https://codelabs.developers.google.com/codelabs/flutter-firebase/#5)
此行指定插件的版本 3.2.1(此时不要使用版本 3.3.0 或 3.3.1)。 有关详细信息,请参阅将 Firebase 添加到您的 Android 项目文档中的添加 SDK 部分(但不要遵循这些说明,因为它们与 Flutter 说明不同)。
build.gradle(项目)
buildscript
dependencies
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:3.2.1'
allprojects
repositories
google()
jcenter()
更新
我还尝试将 gradle 版本更新到 4.6。 文件 -> 项目结构 -> 项目
dependencies
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.google.gms:google-services:4.1.0'
但仍然出现错误。
如果我尝试了 gradle 同步,
Unable to resolve dependency for ':app@dynamicProfile/compileClasspath': Could not resolve project :cloud_firestore.
Unable to resolve dependency for ':app@dynamicProfile/compileClasspath': Could not resolve project :firebase_core.
并尝试构建颤振二进制文件,
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':cloud_firestore:processDebugGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot function without it.
Searched Location:
/Users/kenny/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.0/android/src/nullnull/debug/google-services.json
/Users/kenny/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.0/android/src/debug/nullnull/google-services.json
/Users/kenny/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.0/android/src/nullnull/google-services.json
/Users/kenny/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.0/android/src/debug/google-services.json
/Users/kenny/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.0/android/src/nullnullDebug/google-services.json
/Users/kenny/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.8.0/android/google-services.json
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
Finished with error: Gradle task assembleDebug failed with exit code 1
google-service.json
"project_info":
"project_number": "1234566",
"firebase_url": "https://XXXXXX.firebaseio.com",
"project_id": "XXXXXX",
"storage_bucket": "XXXXXX.appspot.com"
,
"client": [
"client_info":
"mobilesdk_app_id": "1:123456:android:1234567890",
"android_client_info":
"package_name": "com.package.name"
,
"oauth_client": [
"client_id": "client_id.apps.googleusercontent.com",
"client_type": 3
],
"api_key": [
"current_key": "client_key"
],
"services":
"analytics_service":
"status": 1
,
"appinvite_service":
"status": 1,
"other_platform_oauth_client": []
,
"ads_service":
"status": 2
],
"configuration_version": "1"
自行解决
对于cloud_firestore
,使用0.7.4
版本而不是0.8.0
。
更改 gradle 依赖项
dependencies
classpath 'com.android.tools.build:gradle:3.1.2'
...
使用multiDex
这对我有用。
【问题讨论】:
【参考方案1】:Flutterfire 最近推出了仅限 Dart 的初始化,这应该有助于防止发生类似的设置问题。按照他们文档中列出的guide 从手动平台特定设置迁移到仅 Dart 初始化。
【讨论】:
以上是关于Flutter 应用程序未使用 cloud_firestore 插件编译的主要内容,如果未能解决你的问题,请参考以下文章
如何在flutter的firestore中使用uid更新用户数据
Flutter:Flutter Firebase Crashlytics 未针对 iOS 显示
Flutter - 使用 google_sign_in 库时未找到 <Flutter/Flutter.h>