【问题标题】:Firebase connection with Android Studio error: Manifest merger failedFirebase 与 Android Studio 连接错误:清单合并失败
【发布时间】:2019-07-04 00:30:40
【问题描述】:

我想将我的 Android Studio 与 firebase 连接起来。我按照 firebase 网站上的步骤操作,但是当我输入代码时:

implementation 'com.google.firebase:firebase-core:17.0.0'

一个错误来了:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-20:19 to override.

当我像注释一样使用第一行时,错误消失了!

 buildscript {
  repositories {
    google()
    jcenter()

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

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
  }

 allprojects {
    repositories {
      google()
      jcenter()

   }
  }

  task clean(type: Delete) {
     delete rootProject.buildDir
   }

第二个文件

apply plugin: 'com.android.application'

android {
  compileSdkVersion 28
  defaultConfig {
    applicationId "com.example.rentacar"
    minSdkVersion 28
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
  "android.support.test.runner.AndroidJUnitRunner"
  }
   buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android- 
  optimize.txt'), 'proguard-rules.pro'
      }
    }
  }

 dependencies {
   implementation 'com.google.firebase:firebase-core:17.0.0'
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:28.0.0'
   implementation 'com.android.support.constraint:constraint-layout:1.1.3'
   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'

【问题讨论】:

标签: android firebase android-studio


【解决方案1】:
implementation 'com.google.firebase:firebase-core:17.0.0'

此版本的 firbase 库使用 AndroidX 架构组件。

如果您在项目中未使用任何 AndroidX 架构组件,请将您的 firebase sdk 版本降级到 16.0.9。

implementation 'com.google.firebase:firebase-core:16.0.9'

【讨论】:

    【解决方案2】:
    android.useAndroidX=true
    android.enableJetifier=true
    

    gradle.properties 中添加这两行。

    【讨论】:

      【解决方案3】:

      如果您使用的是最新的 firebase SDK,您只需将您的应用迁移到 AndroidX。谷歌说:

      2019 年 6 月,所有适用于 Android 的 Firebase SDK 从 Android 支持库迁移到 Jetpack (AndroidX) 库。 除非您在应用程序中进行以下更改,否则更新的库将不起作用: 将 com.android.tools.build:gradle 升级到 v3.2.1 或更高版本。 将 compileSdkVersion 升级到 28 或更高版本。 更新您的应用以使用 Jetpack (AndroidX);按照迁移到 AndroidX 中的说明进行操作。

      这些是迁移的步骤:

      点击顶部菜单中的重构 -> 重构这个 -> 迁移到 AndroidX

      我添加了屏幕截图以使其更容易。 enter image description here

      enter image description here

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 2020-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多