Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Instant App - Manifest merging error

I have problem with my Android Studio Instant App Project. If I select Manifest.xml in /app directory then select Merger Manifest then I have such error:

Merging Errors: Error: Attribute provider#android.arch.lifecycle.ProcessLifecycleOwnerInitializer@authorities value=(com.theminte.TheMinte.lifecycle-trojan) from AndroidManifest.xml:10:15-75 is also present at AndroidManifest.xml:25:13-68 value=(com.theminte.TheMinte.app.lifecycle-trojan). Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:10:5-201 to override. app main manifest (this file), line 9

Than I cannot start my application with Default Activity, I can only start it with Nothing Activity selected in Project Build Configuration. How to solve this merging issue?

like image 714
Michał Ziobro Avatar asked Jul 14 '18 11:07

Michał Ziobro


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?

So when building your app, the Gradle build merges all manifest files into a single manifest file that's packaged into your app. The manifest merger tool combines all XML elements from each file by following some merge heuristics and by obeying merge preferences that you have defined with special XML attributes.

Where is the AndroidManifest XML file in Android Studio?

Every project in Android includes a Manifest XML file, which is AndroidManifest. xml, located in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements.

What is an AndroidManifest XML file?

The AndroidManifest. xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.


1 Answers

I was able to fix this by changing the <manifest package = ${package} in my base module's manifest.xml to match the project's applicationId.

It appears that androidx.lifecycle:lifecycle-process:2.0.0, a dependency of androidx.lifecycle:lifecycle-extensions:2.0.0, is injecting the provider into base module's manifest with the package defined in the manifest.xml. Per the provider code in lifecycle-extensions/manifest.xml, it looks like it's expected to be the applicationId defined in build.gradle. The provider xml is:

<provider
        android:name="androidx.lifecycle.ProcessLifecycleOwnerInitializer"
        android:authorities="${applicationId}.lifecycle-process"
        android:exported="false"
        android:multiprocess="true" />

The merged manifest in my base module was showing the above provider inserted with an android:authorities value matching the <manifest package:{package} in the base module's manifest.xml instead of the packageId from app/build.gradle.

In the application module I see the provider being injected with the applicationId listed in the application build.gradle. This creates a conflict since there are now two providers with the same android:name="androidx.lifecycle.ProcessLifecycleOwnerInitializer

like image 96
Bryan Avatar answered Oct 20 '22 11:10

Bryan