Merging android manifest files, conflicting filter

℡╲_俬逩灬. 提交于 2019-12-05 06:27:28

For example in the manifest where you want to use only the first activity as launcher you have to add this 2 modifications:

At the beginning of the manifest:

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

And for the activity for which you want to remove the intent filter add this code:

<activity android:name="com.qualcomm.QCARUnityPlayer.QCARPlayerProxyActivity" 
android:label="@string/app_name" android:screenOrientation="portrait" 
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
  <intent-filter tools:node="removeAll">
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

The important part is to add the tools:node="removeAll" attribute in the intent-filter tag

Declare your manifest header like this:

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

And then add one of the following appropriate attributes to the relevant Activity(s):

tools:merge="override"
tools:merge="remove"

Slightly different to @amarkovits answer, I've found success with:

<activity android:name="com.qualcomm.QCARUnityPlayer.QCARPlayerProxyActivity"
          android:label="@string/app_name" android:screenOrientation="portrait"
          android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
          tools:node="merge">
            <intent-filter tools:node="remove"> ...

which I believe will try to merge it first, then replaces just the intent filter causing both Icons on the launcher screen

The Activity that has this intent-filter:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>

is the main Activity that will start on application start up, you can't make both activities work at the same time.

what you should do is let only one Activity ( your main one have this filter) and leave the other one without it.

the second Activity will also be part of the application, but it will not be the first Activity you will see. You can start it by using the startActivity() method.

I have done this, the solution is that when you have multiple flavors, like 1. flavorA, 2. flavorB and main application id is - com.android.vivek

and main flavorA is using com.android.vivek and second flavorB is using com.android.vivek.flavorb

flavorA's manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.android.vivek">

<application xmlns:tools="http://schemas.android.com/tools"
    android:allowBackup="true"
    android:icon="@mipmap/flavorA_ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:replace="android:icon" />

    <activity
        android:name=".ActivitySplash"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        tools:node="replace">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

 </application>

then simply flavorB's manifest mention like below

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.android.vivek">

<application xmlns:tools="http://schemas.android.com/tools"
    android:allowBackup="true"
    android:icon="@mipmap/flavorB_ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:replace="android:icon" />

    <activity
        android:name=".flavorB.SecondActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        tools:node="replace">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".ActivitySplash"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait">

        <intent-filter tools:node="remove">
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

 </application>

when you run flavorA or flavorB then it will work fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!