【问题标题】:Android Studio) Manifest Merger FailedAndroid Studio)清单合并失败
【发布时间】:2020-04-13 15:20:07
【问题描述】:

首先我的模块 build.gradle 是这样的:

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

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

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-firestore:17.1.0'
    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.guava:guava:27.0.1-jre'
    implementation 'com.loopj.android:android-async-http:1.4.9'
}

导致此警告: " 应用 gradle 文件必须依赖 com.google.firebase:firebase-core 才能使 Firebase 服务按预期工作。"

所以我尝试将其添加到(以及更新的 Firestore)中

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

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

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.firebase:firebase-firestore:21.4.2'
    implementation 'com.google.firebase:firebase-core:17.3.0'
    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.guava:guava:27.0.1-jre'
    implementation 'com.loopj.android:android-async-http:1.4.9'
}

但出现此错误

" 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:10:5-46:19 to override. "

我该如何解决?我已经尝试了一些在这里找到的解决方案,但无济于事..提前致谢!如果需要任何其他代码,请告诉我!

【问题讨论】:

标签: java android firebase


【解决方案1】:

您使用的是最新版本的 firestore:

com.google.firebase:firebase-firestore:21.4.2

并且在 2019 年 6 月,firebase 开始支持 androidX,因此您需要迁移到 androidX 才能使用 firebase。

除非您在应用中进行以下更改,否则更新后的库将不起作用:

  1. 将 com.android.tools.build:gradle 升级到 v3.2.1 或更高版本。
  2. 将 compileSdkVersion 升级到 28 或更高版本。
  3. 更新您的应用以使用 Jetpack (AndroidX);按照迁移到 AndroidX 中的说明进行操作。

查看迁移方式:

https://developer.android.com/jetpack/androidx/migrate

【讨论】:

    【解决方案2】:

    实际上,对于同一个库,您有不同来源的不同版本,您有支持库以及他们的AndroidX版本,现在,您可以尝试使用解决它

    tools:replace="android:appComponentFactory
    

    你的错误本身给出的属性。

    转到您的 AndroidManifest 文件添加此属性,如下所示。

    <application
            android:name=".AbcApplication"      
            tools:replace="android:appComponentFactory
            >
    </application>
    

    【讨论】:

      【解决方案3】:

      对我来说,我在 AndroidMenifest.xml 中添加了两个属性

          tools:replace="android:appComponentFactory"
          android:appComponentFactory="androidx"
      

      这样的完整标签:

       <application
          android:allowBackup="true"
          android:icon="@mipmap/logo"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/logo"
          android:theme="@style/AppTheme"
          tools:replace="android:appComponentFactory"
          android:appComponentFactory="androidx"
          tools:ignore="GoogleAppIndexingWarning">
      

      您的项目应该在 Androidx 中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-24
        • 2015-01-27
        • 2020-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多