Flutter应用未使用cloud_firestore插件编译

时间:2018-09-30 11:53:21

标签: android firebase flutter google-cloud-firestore

我已经在google-service.json下添加了android/app。但是尝试构建应用程序时出现错误消息。

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',因为我遵循了代码实验室指南。(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.

并尝试构建flutter二进制文件

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

自我解决方案

对于0.7.4,使用0.8.0版本而不是cloud_firestore

更改gradle依赖项

dependencies {
  classpath 'com.android.tools.build:gradle:3.1.2'
  ...
}

使用multiDex

这对我有用。

0 个答案:

没有答案