簡體   English   中英

Flutter 應用程序未使用 cloud_firestore 插件編譯

[英]Flutter app is not compiled with cloud_firestore plugin

我已經在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

應用程序/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'因為,我遵循了代碼實驗室指南。( 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

這對我有用。

Flutterfire 最近推出了 Dart-only 初始化,這應該有助於防止發生類似的設置問題。 按照他們的文檔中列出的本指南從手動平台特定設置遷移到僅 Dart 初始化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM