Android manifest merge - Different launcher activi

2019-06-24 06:39发布

I have a library project which has the following structure :

    <activity android:name="com.comp.package.activities.A1">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name="com.comp.package.activities.A2">
    </activity>
    <activity android:name="com.comp.package.activities.A3">
    </activity>
    <activity android:name="com.comp.package.activities.A4">
    </activity>

In the app project I want the merged manifest to be :

    <activity android:name="com.comp.package.activities.A2">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name="com.comp.package.activities.A1">
    </activity>
    <activity android:name="com.comp.package.activities.A3">
    </activity>
    <activity android:name="com.comp.package.activities.A4">
    </activity>

Is it possible to achieve this using manifest merger feature?

If I try to have

    <activity android:name="com.comp.package.activities.A2">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

in the base manifest file of the app project, I am getting the following error.

  Trying to merge incompatible /manifest/application/activity[@name=com.comp.package.activities.A2] element:
  <activity
      @android:name="com.comp.package.activities.A2">
  --    <intent-filter>
  --        <action
  --            @android:name="android.intent.action.MAIN">
   <activity
      @android:name="com.comp.package.activities.A2">
  ++</activity>
  ++(end reached)

1条回答
相关推荐>>
2楼-- · 2019-06-24 07:35

Change the AndroidManifest in the consuming app/lib from:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
...
<activity android:name="com.comp.package.activities.A2">

To:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
...
<activity android:name="com.comp.package.activities.A2"
    tools:merge="override">
查看更多
登录 后发表回答