Home > database >  Android How can i override exported tag in manifest?
Android How can i override exported tag in manifest?

Time:11-11

I want to upgrade target sdk from 30 to 31. But i'm getting that error :

Manifest merger failed : android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

When i'm look around in manifest merger. I see one of the third party library which i use in the app didn't add android:exported tag.

 <service android:name="com.****.MessagingService" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

So here is my question. How can i override this service as exported false like below ?

<service android:exported="false"
 android:name="com.****.MessagingService" >
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT" />
                </intent-filter>
            </service> 

CodePudding user response:

You can either replace the whole node

        <service
            tools:node="replace"
            android:name=".MessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

Or just the attribute you need to replace

        <service
            tools:replace="exported"
            android:name=".MessagingService"
            android:exported="false"/>

You can find more information about this topic here

CodePudding user response:

Android Studio will merge all manifest files of your project and its dependencies.

The upper level manifests can always take priority and overwrite the values in the dependencies. Check this paragraph in the documentation.

Since the dependencies do not specify the exported value at all, you can overwrite each service in your top level manifest file like this:

<service android:exported="false"
 android:name="com.****.MessagingService" />

This will merge the values for the service tag for com.****.MessagingService and apply the exported value.

  • Related