安装Firebase后,Flutter无法在Android上运行

问题描述 投票:2回答:3

如果我将firebase_core添加到我的flutter项目,它不会在Android上运行。在iOS中没关系。

我有这个gradle错误。

    Launching lib/main.dart on Android SDK built for x86 in debug mode...
    Initializing gradle...
    Resolving dependencies...
    Running Gradle task 'assembleDebug'...
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

    FAILURE: Build failed with an exception.

    * What went wrong:

        Could not determine the dependencies of task ':firebase_core:compileDebugAidl'.
        > Could not resolve all task dependencies for configuration ':firebase_core:debugCompileClasspath'.
           > Could not find com.google.firebase:firebase-core:.
             Required by:
                 project :firebase_core

  • pubspec:

    dependencies:
      date_format: ^1.0.6
      flutter:
        sdk: flutter

      url_launcher: ^5.0.2
      webview_flutter: ^0.3.5+3
        #path: ./../webview_flutter
      shared_preferences: ^0.5.1+2
      local_auth: ^0.4.0+1
      http: ^0.12.0+1
      xml: ^3.3.1
      #flutter_auth_buttons: ^0.3.1
      flutter_masked_text: ^0.8.0
      path_provider: ^0.5.0+1
      base32: ^1.0.1
      #json_serializable: ^2.0.3
      get_it: ^1.0.3
      rxdart: ^0.21.0
      flutter_html: ^0.9.6
      sqflite: ^1.1.3
      archive: ^2.0.8
      percent_indicator: ^1.0.14
      flutter_statusbarcolor: ^0.2.0
      flutter_inappbrowser: ^1.1.1
      scoped_model: ^1.0.1

      #Firebase
      firebase_core: ^0.3.1+1
      firebase_analytics: ^2.1.1

  • 的build.gradle

    buildscript {
        ext.kotlin_version = '1.2.71'
        repositories {
            google()
            jcenter()
        }

        dependencies {

            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

            classpath 'com.android.tools.build:gradle:3.2.1'
        }
    }

    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
    }

    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'androidx.fragment' &&
                        !details.requested.name.contains('androidx')) {
                    details.useVersion "1.0.0"
                }
            }
        }
    }

  • 应用程序/的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 plugin: 'kotlin-android'
> apply from:
> "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
> 
> android {
>     compileSdkVersion 28
> 
>     sourceSets {
>         main.java.srcDirs += 'src/main/kotlin'
>     }
> 
>     lintOptions {
>         disable 'InvalidPackage'
>     }
> 
>     defaultConfig {
>         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
>         applicationId "xxx"
>         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 {
>     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
>     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'
> 
>     implementation 'com.google.firebase:firebase-core:16.0.8' }
> 
> apply plugin: 'com.google.gms.google-services'

那么我该怎么做才能解决这个问题呢?正如我所说,它适用于iOS,我可以在Firebase控制台中看到Analytics Dashboard。

更多信息...如果我在Android Studio中打开Android模块,则会返回此gradle错误:

gradleerror

firebase flutter flutter-dependencies
3个回答
2
投票

我解决了这个问题。我做了一件疯狂的事,但我的项目正在运行。

我有其他项目与Firebase一起运行良好,所以我开始比较所有版本......几个小时后我发现问题是来自firebase-core 0.3.2依赖的“firebase-bom”。

所以,那是我为解决问题所做的简历:

1)正在运行的项目使用:firebase_core:0.3.1,我的使用firebase_core:0.3.2。 2)我试图使用这个版本0.3.1,但我不知道为什么,在Android Studio中我可以看到来自0.3.2的build.gradle被缓存了。

我意识到,因为在Android Studio上打开android文件夹之后,就可以看到这张图片中的所有依赖项。这个文件的内容与我工作得很好的其他项目不同。

enter image description here

所以我右键单击此build.gradle文件并在finder中打开:

令我惊讶的是,它在firebase-core插件的0.3.2位置打开,但我使用的是0.3.1版本。

/flutter/.普遍-擦车/hosted/普遍.大热天狼.org/firebase_core-0.3.2/Android/build.grad了

所以我做了一件疯狂的事。

我替换了这个文件的所有内容:

/flutter/.普遍-擦车/hosted/普遍.大热天狼.org/firebase_core-0.3.2/Android/build.grad了

我从这里复制了所有内容:

/flutter/.普遍-擦车/hosted/普遍.大热天狼.org/firebase_core-0.3.1+1/Android/build.grad了

区别在于这一行:

实施'com.google.firebase:firebase-bom:17.0.0'

似乎这种“firebase-bom”依赖性破坏了我的项目。

在此之后,我的项目在Android和Firebase上运行良好...我使用Firebase远程配置进行了一些测试,一切正常。

我真的很感激,如果有人能解释我为什么会这样,并且有更好的方法来解决这个问题。


0
投票

使用更改您的存储库部分

repositories {
            jcenter()
            maven { url 'https://maven.google.com' }
        }

作为存储库google()只是在Gradle 4+中提供的maven { url 'https://maven.google.com' }的简写,如this answer中所述。


0
投票

在pubspec.yaml中进行一些小改动。使用firebase_core更改firebase_core:^ 0.3.1 + 1版本:0.3.1 + 1。只需删除^。 firestore创建此问题的新更新。

© www.soinside.com 2019 - 2024. All rights reserved.