【问题标题】:Firebase_database plugin for flutter is not working (resolve android.arch.core:common:1.1.1.)颤振的 Firebase_database 插件不起作用(解决 android.arch.core:common:1.1.1。)
【发布时间】:2020-03-10 05:40:29
【问题描述】:

我是 Flutter 开发的新手。我想使用 firebase 数据库。我能够使用 firebase 分析插件连接到 firebase,但未能成功使用 firebase 数据库。

我试图在某个时间添加插件以知道问题出在哪里并且知道我确定它是 firebase_database 插件。

我已经成功添加了以下包:

firebase_core: ^0.4.0+9
firebase_analytics: ^5.0.2
firebase_auth: ^0.14.0+5

但是当我添加时

firebase_database: ^3.1.0

我收到以下错误 以错误结束:Gradle 任务 assembleDebug 失败,退出代码为 1

当我在我的 Android 手机上运行默认的颤振应用程序(计数器应用程序)时出现此错误。 因此,我在 Android Studio 中打开 Android 模块以获取有关该错误的更多详细信息。 我收到以下错误


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:1.1.1.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:common:1.1.1.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:common:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database


ERROR: Failed to resolve: com.google.firebase:firebase-common:16.0.6
Show in Project Structure dialog
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.core:common:{strictly 1.0.0}.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.core:common:1.1.1.
Show Details
Affected Modules: firebase_database


ERROR: Unable to resolve dependency for ':firebase_database@debug/compileClasspath': Could not resolve android.arch.lifecycle:runtime:1.0.0.
Show Details
Affected Modules: firebase_database

这是我的 pubspec.yaml 文件


version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

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.2
  firebase_core: ^0.4.0+9
  firebase_analytics: ^5.0.2
  firebase_auth: ^0.14.0+5
  firebase_database: ^3.1.0


dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/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

另外,下面是我的项目级别 my build.gradle


buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
        classpath 'com.google.gms:google-services:4.3.3'
    }
}

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
}

下面是我的应用级 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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.labstabs.riskometer"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        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.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

【问题讨论】:

  • 在您的项目 build.gradle 中尝试 classpath 'com.android.tools.build:gradle:3.3.2'classpath 'com.google.gms:google-services:4.3.2'。让我们知道更改这些版本后是否也会引发相同的错误
  • 它确实抛出了以下错误:Finished with error: Gradle task assembleDebug failed with exit code 1. 要获得更多详细信息,我必须在 Android Studio 中打开 Android mobule。我发现它抛出了与上面完全相同的错误。

标签: firebase firebase-realtime-database flutter build.gradle


【解决方案1】:

用这个替换

classpath 'com.google.gms:google-services:4.2.0'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2018-11-17
    • 2021-02-20
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多