Search code examples
androidgradlemanifest

Android How can i override exported tag in manifest?


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> 

Solution

  • 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.