Почему я получаю сообщение «Ошибка слияния манифеста» после добавления Firebase Storage в мой build.gradle?

Я использую Firebase в своем проекте Android. В частности: Firebase Firestore, Firebase Authentication и Firebase Cloud Messaging.

Сегодня я решил добавить Firebase Storage к своему build.gradle, так как мне нужны были функции хранения. Теперь я получаю сообщение об ошибке при создании проекта:

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:8:5-214:19 to override.

Вот мой build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myproject.myproject"
        minSdkVersion 23
        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 fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.google.firebase:firebase-firestore:18.2.0'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'
//    implementation 'com.google.firebase:firebase-storage:18.1.1' // this seems to be causing the error
    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.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
    implementation 'de.siegmar:fastcsv:1.0.3'
    implementation 'com.github.bumptech.glide:glide:4.9.0'

}

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

Я попытался добавить tools:replace = "android:appComponentFactory" к тегу <application> в моем манифесте, как предполагалось в ошибке, но добавление не устранило ошибку.

Я также хотел бы отметить, что только зависимость implementation 'com.google.firebase:firebase-storage:18.1.1' в моем градиенте находится в последней версии (на момент написания этой статьи).

Ниже приведены зависимости Firebase, не относящиеся к последней версии:

    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.google.firebase:firebase-firestore:18.2.0'
    implementation 'com.google.firebase:firebase-messaging:17.6.0'

Я уже пытался обновить приведенные выше зависимости до последней версии и выполнить сборку, но все равно получаю ту же ошибку Manifest merger failed.

Кто-нибудь знает, как исправить эту ошибку?

Переход на AndroidX. Вот один из моих отвечать

Taseer Ahmad 29.07.2019 09:38

Быстрый момент: вы должны объявлять переменные для версии с общими зависимостями

Paresh Mayani 29.07.2019 09:46
0
2
221
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Ответ принят как подходящий

Вам нужно перейти на AndroidX. Версия firebase-storage, которую вы используете, требует, чтобы AndroidX работал правильно, из документы:

This release is a MAJOR version update and includes breaking changes. With this release, libraries are migrated from the Android Support Libraries to the Jetpack (AndroidX) Libraries. The updated libraries will not work unless you make the following changes in your app:

  1. Upgrade com.android.tools.build:gradle to v3.2.1 or later.
  2. Upgrade compileSdkVersion to 28 or later.
  3. Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.

Также проверьте следующую ссылку, чтобы узнать, как выполнить миграцию:

https://developer.android.com/jetpack/androidx/мигрировать

Это два способа решить эту проблему.

Первый: 1) Перенесите проект в AndroidX.

Два: 1) Понизить зависимость от огневой базы.

Из этого:-

реализация 'com.google.firebase:firebase-core:11.8.0'

реализация 'com.google.firebase:firebase-messaging:11.8.0'

Другие вопросы по теме