How to modify Android Manifest permission coming form the merged manifest?

290 Views Asked by At

I've seen how to remove a permissions, for example Android Gradle Manifest Merger: Override 'uses-permission' attribute coming from a library. You can also add a new permission simply featuring it in your own Manifest file.

But what if you neither want to remove, nor add, but just modify. For example for Android 12 and 13 the location permission is not required if your app only deals with Bluetooth. In the past fro Bluetooth you must have specified location permissions, see https://www.androidpolice.com/2021/05/19/android-12-apps-wont-ask-for-location-permissions-when-all-they-want-is-bluetooth-scanning-which-yes-was-a-thing/

My context is a Flutter application's Android platform version, and by the new rules one of the permissions is

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />

That's great for applications would wouldn't need location permission. However if the application would actually legitimately need location permission, how can it modify this permission coming from the plugin dependencies' merged permissions? It'd need the regular

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

and also the coarse and fine location permissions, which can be simply added. Reference issue: https://github.com/boskokg/flutter_blue_plus/issues/409

1

There are 1 best solutions below

1
On BEST ANSWER

You should be able to use tools:remove, as is covered in the documentation on manifest merger.

So, try this in your manifest:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:remove="android:usesPermissionFlags"/>