繁体   English   中英

Flutter 谷歌地图和 Firebase 无法协同工作

[英]Flutter google maps and firebase not working together

我在我的应用程序中使用 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 或单独使用谷歌地图,它可以正常工作但不能一起使用

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

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

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

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

您需要在应用级build.gradle文件中为FirebaseAuth添加原生依赖项,如下所示:

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

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

您可以从此媒体链接中获得参考,该链接清楚地显示了将Firebase添加到flutter项目中的方法。

https://medium.com/enappd/adding-firebase-to-your-flutter-app-281b8f391b47

看来您是手动迁移到 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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM