11

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.

Community
  • 1
  • 1
Steffen
  • 2,197
  • 2
  • 24
  • 38

1 Answers1

12

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks but changing the element to did not help. The app still asks for permission to access the SC card. Am I using it in the correct element of my manifest file? – Steffen Jan 15 '15 at 12:30
  • @sdeff: I have no idea if your `com.helpshift` is right for the `selector`, as I don't use this library. Beyond this, look at the manifest merger report (should be in `build/output/apk/` IIRC) and see if it gives you any clues. – CommonsWare Jan 15 '15 at 12:50
  • 1
    I just completely removed `tools:selector="com.helpshift"` and now it's seems to be working. That should be okay now? Btw. the library has an in-app chat where users can attach screenshots. That's not working anymore now but it's better than 1-star ratings of users who think I just want to get their personal data. :) – Steffen Jan 15 '15 at 12:55
  • @sdeff: "That should be okay now?" -- I cannot really answer that, as it's not my app or my library. Not having a selector means that if you add another library that requires this permission, the permission will still be suppressed. – CommonsWare Jan 15 '15 at 12:56
  • That's the only library which needs that permission. But thanks for the additional info. I'm going to search for the correct selector name. Shouldn't this just be the package name of the library? – Steffen Jan 15 '15 at 13:00
  • @sdeff: "That's the only library which needs that permission" -- today, that may be true. You may add or upgrade libraries, though. "Shouldn't this just be the package name of the library?" -- in terms of the `package` attribute in the library project's manifest, yes, AFAIK. – CommonsWare Jan 15 '15 at 13:04
  • That's strange, because their package name in their library manifest file is exactly `package="com.helpshift"` but with `tools:selector="com.helpshift"` it's not working. I still wonder what's wrong with the selector but your answers already helped me alot. Thanks! – Steffen Jan 15 '15 at 13:15
  • 1
    @sdeff: If you temporarily comment out your override of the permission, the manifest merger report should tell you where it is getting the `WRITE_EXTERNAL_STORAGE` permission from, and that may give you some clues as to why `com.helpshift` as the `selector` is not working. Or, just go without the `selector`, if you are sure that you never want this permission. – CommonsWare Jan 15 '15 at 13:17
  • The `manifest-merger-release-report.txt` says `uses-permission#android.permission.WRITE_EXTERNAL_STORAGE ADDED from com.helpshift:android-aar:3.7.1:9:5`. But the only selector that is accepted as a valid library identifier is `com.helpshift`?! – Steffen Jan 15 '15 at 13:30
  • 1
    @sdeff: Yeah, I'm stumped. I have filed [a feature request](https://code.google.com/p/android/issues/detail?id=97622) to have the manifest merger report provide more information here. – CommonsWare Jan 15 '15 at 13:43
  • Thanks anyway. I really appreciate your effort! – Steffen Jan 15 '15 at 14:02
  • 1
    FWIW, I tried with a selector and can see a "uses-permission ... REJECTED from", but then the permission is still present in the resulting APK. Removing the selector results in the same output, however the APK no longer have the permission. Clearly bugged behavior. – 3c71 Mar 02 '15 at 18:31