6

I'm trying to combine android manifest files from 2 plugins in Unity, but there are two activities with the same intent-filter and I can only get 1 or the other to work at the same time....

Of the 2 conflicting activities, whichever is on top in the manifest file is the one that will work. So if activity from manifest #1 is on top, plugin #1 will work but not #2, and vice versa.

The two conflicting activities are:

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

And:

<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>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

is there any way I can merge the two and get them to work from the same app? I'm using Unity 3d.

user1108224
  • 159
  • 1
  • 15
  • you should know which activity you want to use as entry point, shouldn't you ? – njzk2 Nov 05 '13 at 18:13
  • using Unity I don't normally work directly with activities....I didn't write the activities I bought them as a plugin...they work independently but not when combined.... – user1108224 Nov 05 '13 at 18:36
  • Did you end up figuring this out? I'm stumped. – Ryan Martin May 29 '14 at 20:07
  • Possible duplicate of [Gradle: How to merge Android manifest files for different buildTypes which need the same Activity, but with different intent-filters](http://stackoverflow.com/questions/18708076/gradle-how-to-merge-android-manifest-files-for-different-buildtypes-which-need) – tir38 Apr 21 '16 at 02:55

5 Answers5

6

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

amarkovits
  • 776
  • 1
  • 10
  • 17
2

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"
swooby
  • 3,005
  • 2
  • 36
  • 43
2

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

AllDayAmazing
  • 2,383
  • 1
  • 24
  • 25
1

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.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
0

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

Vivek Hande
  • 929
  • 9
  • 11