Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging activity intent-filter categories with Gradle

With Gradle is it possible to add <category android:name="android.intent.category.HOME"/> to the intent filter of an activity in a flavor manifest?. My flavor manifest contains an activity with the same name as the base manifest, but I get the following from lint: Error: Duplicate registration for activity com.xxx.MainActivity [DuplicateActivity]

Also, by ignoring Lint I can get a merger but the resulting manifest has both intent-filter blocks from the base and flavor manifests instead of a combination of the two.

Gradle version is 0.12.+ of which the docs seem to imply it's possible.

The main manifest contains the following activity:

<activity
        android:name=".MainActivity">
    <intent-filter>
        <action android:name="com.reveldigital.player.RESTART"/>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
    <intent-filter>
        <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
    </intent-filter>

    <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter"/>
</activity>

The flavor manifest contains:

<activity android:name="com.xxx.MainActivity">
            <intent-filter>
                <action android:name="com.reveldigital.player.RESTART"/>
                <action android:name="android.intent.action.MAIN"/>

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

The result I get is something like this:

<activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="com.reveldigital.player.RESTART"/>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
<intent-filter>
                    <action android:name="com.reveldigital.player.RESTART"/>
                    <action android:name="android.intent.action.MAIN"/>

                    <category android:name="android.intent.category.DEFAULT"/>
                    <category android:name="android.intent.category.HOME"/>
                </intent-filter>
        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
        </intent-filter>

        <meta-data
                android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                android:resource="@xml/device_filter"/>
</activity>
like image 470
Weezelboy Avatar asked Mar 18 '23 06:03

Weezelboy


1 Answers

On you manifest add the following:

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

If all you wanna do is replace the activity then, on your Flavor Manifest add tools:node="replace" like so:

<activity android:name=".MainActivity" 
        tools:node="replace">
        <intent-filter>
            <action android:name="com.reveldigital.player.RESTART"/>
            <action android:name="android.intent.action.MAIN"/>

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

For more info check out: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger

like image 178
Frank Hernandez Avatar answered Mar 21 '23 16:03

Frank Hernandez