For my app that I'm developing with the latest Android Studio I'm using this dependencies within it's gradle file:
dependencies {
compile 'com.android.support:support-v4:21.0.+'
compile 'com.helpshift:android-aar:3.7.1'
}
The com.helpshift:android-aar:3.7.1
library needs the following permission for a feature that I don't use in my main app:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
As described here and here I can override attributes from the imported library’s activity XML declarations.
But can I also override manifest XML declarations like the mentioned uses-permission
?
I already tried something like this in my main manifest, but it didn't work:
<permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:node="remove"
tools:selector="com.helpshift">
</permission>
Also changing the <permission>
element to <uses-permission>
did not help. The app still asks for permission to access the SC card.
My main AndroidManifest.xml looks like this now:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:installLocation="auto"
xmlns:tools="http://schemas.android.com/tools"
package="com.bmi.rechner" >
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:node="remove"
tools:selector="com.helpshift">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
...
Update: The suggested answer by @CommonsWare is working.
It's just my tools:selector="com.helpshift"
which isn't correct. I'm leaving it out because I'm sure I won't need that permission in any other libraries for a while.
He also filed a feature request to improve the Manifest Merger Report which might help to find the right selector in the future.
So when building your app, the Gradle build merges all manifest files into a single manifest file that's packaged into your app. The manifest merger tool combines all XML elements from each file by following some merge heuristics and by obeying merge preferences that you have defined with special XML attributes.
Suggestion: add 'tools:replace="icon"' to <activity> element at AndroidManifest.xml:1:5 to override A “blame” type of output can be obtained to qualify each element and attribute resulting in the merged XML with some indication of where the element/attribute originated from. Each element type has a specific default merging policy attached to it.
So when building your app, the Gradle build merges all manifest files into a single manifest file that's packaged into your APK. The merger tool combines all the manifest files into one file by merging them sequentally based on each manifest file’s priority.
When merging two manifest files, the merger tool looks for these markers in the higher-priority manifest file. All markers belong to the Android tools namespace, so you must first declare this namespace in the <manifest> element as shown here:
It would be a <uses-permission>
element that you would remove
, not a <permission>
element.
And note that the library may crash if your app does not hold this permission.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With