【Android】Manifest merger failedとかいうエラーの解消法
発生したエラー
以前udemyで作成したAndroidアプリのプロジェクトを開き、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.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-30:19 to override.
とかいうエラーが出てきた。
本記事は、その解消法を備忘録として残したいと思います。
同じエラーで苦しんでいる方のお力になれれば幸いです。
解決方法
結論から先に言うと、
①【gradle.properties】に
android.useAndroidX=true android.enableJetifier=true
を記載。
②MainActivity等の、AppCompatActivityを継承しているファイルを開き、
import androidx.appcompat.app.AppCompatActivity
をインポートする。
③layoutファイルでConstraintLayout棟のサポートライブラリを使用している場合は、
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" > //省略 </androidx.constraintlayout.widget.ConstraintLayout>
と書き換える。