8

Since downloading the latest SDK and installing Android Studio, my project fails to build. I get the following message:

Manifest merger failed with multiple errors


My gradle app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.clupascu.oavm"
        minSdkVersion 21
        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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.github.chrisbanes:PhotoView:2.2.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'
}

My Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.app.clupascu.oavm">

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

        <activity
            android:name=".MainPage"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".FirstObchodni"
            android:label="@string/obchodn_akademie"/>

        <activity android:name=".SecondObchodni"
            android:label="@string/_2_obchodn_akademie"/>

        <activity android:name=".VysiiOdborna"
            android:label="@string/_3_vy_odborn_kola"/>
    </application>

</manifest>

In Merged Manifest is written this:

Merging Errors: Error: tools:replace specified at line:6 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 5 Error: Validation failed, exiting app main manifest (this file) 

I tried a lot of solutions from other questions, but without result, Thanks a lot.

simpller
  • 317
  • 1
  • 2
  • 14

2 Answers2

13

I faced the same situation while implementing the maps api in my application. I solved it by adding the following code in AndroidManifest.xml and Gradle.properties file.

In AndroidMainfest.xml added this code

    android:appComponentFactory="androidx.core.app.CoreComponentFactory"
    tools:replace="android:appComponentFactory"

In gradle.properties added this code

   android.useAndroidX=true
   android.enableJetifier=true
sai Pavan Kumar
  • 1,129
  • 12
  • 20
4

"tools:replace="android:appComponentFactory" <- this line you're saying to Manifest merger that you're going to provide new value for android:appComponentFactory attribute but you're not doing so. So as I see it you have two options:

  1. Remove tools:replace="android:appComponentFactory"

  2. Provide new value for android:appComponentFactory" attribute

Hope it helps.

Nikolay Ivanov
  • 8,897
  • 3
  • 31
  • 34
  • I removed tools:replace="android:appComponentFactory" and another Manifest error appeared `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 element at AndroidManifest.xml:6:5-34:19 to override. ` – simpller Oct 23 '18 at 12:54
  • You should choose witch one to use. Manifest merger tells you that there two possible values for this attribute coming from libraries you're using. – Nikolay Ivanov Oct 23 '18 at 13:00
  • Can you tell me please how to do this ? – simpller Oct 23 '18 at 13:02
  • 2
    answering to your question add android:appComponentFactory="androidx.core.app.CoreComponentFactory". but its just a symptom it looks like your project s dependant on both support library and jetpack library, are you sure you want to this? – Nikolay Ivanov Oct 23 '18 at 18:11
  • @simpller can you please tell how you solved this issue? – khushbu May 13 '19 at 08:05
  • I ignored the latest versions of appcompat and design from implementations. – simpller May 14 '19 at 09:07
  • What is the new value ? – Gyan Swaroop Awasthi Sep 24 '20 at 13:58