【问题标题】:Flutter google maps and firebase not working together颤振谷歌地图和火力基地不能一起工作
【发布时间】:2020-03-25 19:51:42
【问题描述】:

我在我的应用中使用 google map 和 firebase,但应用无法编译并引发以下错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.android.support:support-v4:26.1.0' is set to compileOnly/provided 
which is not supported

以下是我的 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.")
}

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 "com.squadtechs.www.bus_tracking_app"
    minSdkVersion 16
    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'
}
apply plugin: 'com.google.gms.google-services'

以下是我的模块级 build.gradle 文件

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

dependencies {
        classpath 'com.google.gms:google-services:4.3.2'
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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
}

要记住的要点

  1. 我已迁移到 androidX,但问题仍然存在
  2. 如果我单独使用 firebase 或单独使用谷歌地图,它可以正常工作,但不能一起使用

【问题讨论】:

  • Firebase 和消息包之间似乎存在依赖冲突,请尝试降级?
  • 试过但没有成功

标签: android firebase google-maps flutter dart


【解决方案1】:

在您的应用级别 build.gradle 文件中添加 firebase auth 依赖项,如下所示

implementation 'com.google.firebase:firebase-auth:19.2.0'

【讨论】:

  • 谢谢@Aneeq,我会检查并告诉你
  • 工作正常,我在app/buils.gradle 中添加了 Auth 依赖项,它有效,添加了 maps 依赖项(由 @Ali 回答),它有效。谢谢回答
【解决方案2】:

将此添加到您的app/build.gradle

implementation 'com.google.maps.android:android-maps-utils:0.5'

【讨论】:

  • 它有效,我不知道为什么,但它解决了我的问题,@Aneeq 的 asnwer 也是如此
【解决方案3】:

您需要在应用级别的build.gradle 文件中为FirebaseAuth 添加本机依赖项,​​如下所示:

implementation 'com.google.firebase:firebase-auth:19.2.0'

您可以将Google Maps 依赖项放在同一个文件中,例如: implementation 'com.google.maps.android:android-maps-utils:0.5'

【讨论】:

    【解决方案4】:

    您似乎手动迁移到 androidX。尝试替换app/build.gradle中的这些行:

       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    到:

       testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    

    到:

        androidTestImplementation 'androidx.test:runner:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    

    【讨论】:

    • firebaseauthmaps 添加依赖解决了它
    猜你喜欢
    • 2021-06-05
    • 2021-03-10
    • 2021-03-19
    • 2021-07-03
    • 2020-07-19
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    相关资源
    最近更新 更多