【问题标题】:Getting a simple app to work with Cloud Firestore让一个简单的应用程序与 Cloud Firestore 一起使用
【发布时间】:2018-09-15 17:38:21
【问题描述】:

我正在关注来自站点 https://pub.dartlang.org/packages/cloud_firestore#-readme-tab- 的示例。我遵循了 README.md 中有关 Android 应用程序的所有说明。在 Firebase 控制台中创建一个 Android 应用,复制 google-services.json 并更新两个 buidl.gradle 文件,如下所示:

android/build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        // Add this line
        // **********************************
        classpath 'com.google.gms:google-services:3.2.0'
        // **********************************
    }
}

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
}

android/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.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.fluttercloudfirestore"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    // Add this line
    // **********************************
    compile 'com.google.firebase:firebase-core:12.0.0'
    // **********************************
}

// Add to the bottom of the file
// **********************************
apply plugin: 'com.google.gms.google-services'
// **********************************

还更新了我的 pubspec.yaml

name: flutter_cloud_firestore
description: A new Flutter project.

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  cloud_firestore: "^0.4.0"


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies, 
  # see https://flutter.io/custom-fonts/#from-packages

当我运行 flutter packages get 时,我收到以下错误:

在 flutter_cloud_firestore 中运行“flutter packages get”... 包 cloud_firestore 没有匹配 >=0.4.0

根据this页面,0.4.0是当前版本。什么给了?

【问题讨论】:

    标签: android dart google-cloud-firestore flutter


    【解决方案1】:

    没有简单的方法可以从包主页或pub 包管理器的错误消息本身中分辨出来,但 Flutter 的 beta 频道(这是本文的默认设置)无法使用它,所以你必须切换到dev频道。

    您可以使用flutter channel 命令更改您所在的发布频道。在这种情况下,如果您对使用0.4.0 不放心,您需要在dev 频道上:

    $ flutter channel dev
    $ flutter doctor // May not be strictly necessary, but a good check
    

    那么$ flutter packages get 应该会正确获取包。

    【讨论】:

    • 谢谢,我切换到 0.3.2 并且它得到了包就好了。问题: 1) 我如何知道 can_firestone 页面是否是软件包主页,该软件包是在稳定/测试版还是开发频道上?我希望能够自己做出这个决定,而无需联系 StackOverflow。
    • 没问题。当我查看它时,我唯一能找到的就是这个差异,它突破了所需的flutter 版本:github.com/flutter/plugins/commit/… 从理论上讲,您可以运行$ flutter --version 来确定您正在运行哪个版本并查看它是否属于依赖项的pubspec.yaml。有点烂。
    • 另外请注意,我是在假设您和我在 stable 频道上进行操作的情况下进行操作的,但由于 Flutter 处于测试阶段,因此没有这样的频道。
    猜你喜欢
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-23
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多