Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Manifest Merger fails after adding Dependency com.google.android.material

We would like to use the most current material design ui elements presented by Google. Therefore I added com.google.android.material:material:1.0.0-beta01 in our projects gradle file. But since then I get the following error.

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

Without the material library everything works fine.

What I already tried

  1. I changed the ordering of the dependencies (which did obviously not work)
  2. I also tried to add tools:replace="android:appComponentFactory" to our Manifest file as suggested in the error message. But this left me with a new error message:

java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:524) at com.android.build.gradle.tasks.ProcessManifest.doFullTaskAction(ProcessManifest.java:75) at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)

I checked the log file but the only warning shown in idea.log is

2018-08-08 11:08:21,500 [thread 267] WARN - .tools.idea.model.ManifestInfo - getMergedManifest failed Manifest merger failed with multiple errors, see logs 2018-08-08 11:08:21,642 [thread 267] WARN - .tools.idea.model.ManifestInfo - getMergedManifest failed Manifest merger failed with multiple errors, see logs 2018-08-08 11:08:21,917 [J pool 0/7]

More information

API Version

android {
compileSdkVersion 28
buildToolsVersion '28.0.0'

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
}

(the same API is chosen in file > project structure in Android Studio)

Dependencies:

dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')

/** ANDROID LIBRARIES  **/
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
api 'com.android.support:support-v13:28.0.0-beta01'
api 'com.google.android.material:material:1.0.0-beta01'
api 'com.android.support:design:28.0.0-beta01'
api 'com.android.support:preference-v7:28.0.0-beta01'
api 'com.android.support:cardview-v7:28.0.0-beta01'
api 'com.android.support:customtabs:28.0.0-beta01'
api 'com.android.support:support-v4:28.0.0-beta01'

/** GOOGLE PLAY SERVICE  **/
api 'com.google.android.gms:play-services-auth:15.0.1'

api 'com.google.android.gms:play-services-drive:15.0.1'
api 'com.google.android.gms:play-services-fitness:15.0.1'
api 'com.google.android.gms:play-services-maps:15.0.1'
api 'com.google.android.gms:play-services-wearable:15.0.1'
api 'com.google.android.gms:play-services-vision:15.0.2'

api 'com.google.firebase:firebase-core:16.0.1'
api 'com.google.firebase:firebase-perf:16.0.0'
api 'com.crashlytics.sdk.android:crashlytics:2.9.4'

//sunrise and sundown calculation for map day and night mode
api 'com.luckycatlabs:SunriseSunsetCalculator:1.2'

/** GOOGLE MAPS  **/
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.code.gson:gson:2.8.0'

/** EXTERNAL LIBRARIES  **/

implementation 'org.osmdroid:osmdroid-android:5.6.5'
implementation 'org.osmdroid:osmdroid-mapsforge:5.6.5'
implementation 'org.mapsforge:mapsforge-map-android:0.6.1'
implementation 'org.mapsforge:mapsforge-map:0.6.1'
implementation 'com.caverock:androidsvg:1.2.2-beta-1'

//dropbox api
implementation 'com.dropbox.core:dropbox-core-sdk:3.0.6'    

androidTestImplementation 'junit:junit:4.12'
implementation files('libs/samsung-health-data-v1.3.0.jar')}

Manifest

<manifest
package="com.user.libraries.bluetooth"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.VIBRATE"/>    

<application
    tools:replace="android:appComponentFactory"
    android:allowBackup="true"
    android:supportsRtl="true">
    <service android:name="com.user.libraries.location.LocationService" />
    <service android:name="com.user.libraries.location.BleLocationTrackerService" />
    <service android:name="com.user.libraries.sensors.SensorService"/>

    <service android:name="com.user.libraries.sharing.DataExchangerService"/>

    <receiver
        android:name="com.user.libraries.bluetooth.BluetoothStateReceiver"
        android:enabled="true">
        <intent-filter>
            <action android:name="android.bluetooth.adapter.action.STATE_CHANGED"/>
        </intent-filter>
    </receiver>

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
    </provider>

</application>

Any idea how I can solve this issue?

like image 541
little_planet Avatar asked Aug 08 '18 09:08

little_planet


People also ask

How do I fix manifest merger failed?

Try adding the following labels to resolve the issue: Add the xmlns:tools line in the manifest tag. Add tools:replace= or tools:ignore= in the application tag.

How do I merge manifest files on Android?

If two manifests have the same XML element, then the tool merges the two elements together using one of three merge policies: Merge. Combine all non-conflicting attributes into the same tag and merge child elements according to their respective merging policy.

What are manifests in Android Studio?

The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.


2 Answers

Don't forget to add

android.useAndroidX=true
android.enableJetifier=true

to your gradle.properties. I always forget this when I get on a new machine because gradle.properties is not in source control. Would be great if we got a sensible error in this case.

like image 54
Daniel Wilson Avatar answered Oct 04 '22 14:10

Daniel Wilson


Main problem here is that you are adding

com.google.android.material:material:1.0.0-beta01

that belongs to newly released androidx package and nowadays it is not compatible with android support library that you have in your dependencies.

You have 2 options:

  1. Replace com.google.android.material:material:1.0.0-beta01 with com.android.support:design:28.0.0-beta01 (see all support libraries https://developer.android.com/topic/libraries/support-library/packages) (that I recommend)
  2. Use Android Studio option Refactor to AndroidX (see https://material.io/develop/android/docs/getting-started/) (I do not recommend)

Here is sample of working code:

 <android.support.design.widget.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        app:boxStrokeColor="@color/colorAccent"
        app:boxStrokeWidth="5dp">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/messageEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

 </android.support.design.widget.TextInputLayout>
like image 30
redlabrat Avatar answered Oct 04 '22 16:10

redlabrat