Manifest merger failed with multiple errors is a common problem in android development. In this post, I will tell you what is the reason behind that, What necessary change you have to do to fix it in your project.
When manifest merger failed problem occur
- You have created a project with appcompat and design lib, now trying to add material io dependencies in the same project. That time you mostly faced Manifest merger failed with multiple errors problem.
- Another scenario is you have created a project with androidx and trying to add design, support lib than same problem will occur.
Somethings like below
dependencies { //... implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' // materail io implementation 'com.google.android.material:material:1.0.0' }
Why manifest merger failed problem occur
It happened because we should not use the com.android.support and com.google.android.material dependencies in the app at the same time
AndroidX
As you know we have used Android Support Library for providing backward compatibility last 7 years. Over the years, this library has grown in adoption as the majority of apps.
However, it hasn’t always been straight-forward, Overtime Support Library complexity was increasing day by day. So the Android team decided to refactor and combined the Support Library into a new set of extension libraries known as AndroidX.
Google launched the new Android extension libraries called AndroidX in May 2018. This includes simplified and well define package names to better indicate each package’s content and it’s also supported API levels. This has provided a clear separation from what packages are bundled with Android OS, and those that are an extension of it.
I’m delighted to bring you initial support for AndroidX packages today.
Artifact Mappings AndroidX
AndroidX is a redesign of the Android Support Library, then how do you know what new library has and what is new name. Basically, Google made a great mapping of the original support library API packages into the androidx namespace. Only the package and dependency names changed, class, method, and field names did not change.
Package Name Change
Old | New |
android.support.** | androidx.@ |
android.design.** | com.google.android.material.@ |
android.support.test.** | androidx.test.@ |
android.arch.** | androidx.@ |
android.arch.persistence.room.** | androidx.room.@ |
android.arch.persistence.** | androidx.sqlite.@ |
For more details read official, see the following documentation.
How to resolve manifest merger failed problem
You saw the android team is redesigned the support library to androidx. Let’s see your project, If you are using androidx, than remove support and design library nd add material library. Now build the app and see all things working fine now
Create a new New Project with AndroidX
Now I’m going to demonstrate how to build a project with androidx and material io. Let’s move to Android Studio and create a new project with androidx.
Add the dependency in app gradle
dependencies { implementation 'androidx.appcompat:appcompat:1.0.2' // materail io implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' }
Now sync and rebuild our project. You see there is no error with sync. But build finished with some compilation error. That’s because we are using import from now unknown library (android.support)
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Let replace all import with androidX
//import android.support.v7.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Nice! All Done!
Go to resource layout
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <android.support.v7.widget.CardView android:layout_width="0dp" android:layout_height="0dp" android:layout_marginBottom="16dp" android:layout_marginEnd="16dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginStart="16dp" android:layout_marginTop="16dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" > <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.v7.widget.CardView> </android.support.constraint.ConstraintLayout>
Now see here we are using support library component, So need to change in androidx
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <androidx.cardview.widget.CardView android:layout_width="0dp" android:layout_height="0dp" android:layout_marginBottom="16dp" android:layout_marginEnd="16dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginStart="16dp" android:layout_marginTop="16dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" > <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.cardview.widget.CardView> </androidx.constraintlayout.widget.ConstraintLayout>
Rebuild your project and run the application, you see your app is up and running.
Conclusion
In this post, we set up a new project with AndroidX)that replaces one package from the android support library. We also added new design library from google to support material io and now you can use any component of design in our project
Keep in touch
If you want to keep in touch and get an email when I write new blog posts, follow me on facebook or subscribe us. It only takes about 10 seconds to register.
Still, if you have any queries please put your comment below.
4 Comments
i am facing a problem for manifest merger failed with multiple errors see the logs but i can’t understand how to solve this please help in this regards.
i am facing a problem for manifest merger failed with multiple errors see the logs but i can’t understand how to solve this please help in this regards.
Hi, I am new in this field and I have a problem. I can sync my project without any problem. but I cannot build APK. I just migrated my project to AndoidX
there is this error: “Manifest merger failed with multiple errors, see logs”. Please help me to solve it.
this is the code:
What if I don’t want to use androidx?