31

I noticed that the following permissions were automatically added when i use the following in my build.gradle file

compile 'com.google.android.gms:play-services:7.5.0'

This did not occur with the earlier versions of the play-services. does anyone have a solution to remove these unwanted permissions?

I am only using the ads function (INTERNET and ACCESSNETWORK_STATE). I got no need for the LOCATION and USE_CREDENTIALS permissions. How do you remove these unwanted permissions?

I noticed that the 'manifest-merger-xxx-debug-report.txt' file contains the following

 ...<snipped bunch of other merges>
MERGED from com.google.android.gms:play-services-maps:7.5.0:22:5
    android:name
        ADDED from com.google.android.gms:play-services-maps:7.5.0:22:22
uses-permission#android.permission.ACCESS_COARSE_LOCATION
ADDED from com.google.android.gms:play-services-maps:7.5.0:23:5
MERGED from com.google.android.gms:play-services-maps:7.5.0:23:5
MERGED from com.google.android.gms:play-services-maps:7.5.0:23:5
MERGED from com.google.android.gms:play-services-maps:7.5.0:23:5
    android:name
        ADDED from com.google.android.gms:play-services-maps:7.5.0:23:22
uses-feature#0x00020000
ADDED from com.google.android.gms:play-services-maps:7.5.0:24:5
MERGED from com.google.android.gms:play-services-maps:7.5.0:24:5
MERGED from com.google.android.gms:play-services-maps:7.5.0:24:5
MERGED from com.google.android.gms:play-services-maps:7.5.0:24:5
    android:glEsVersion
        ADDED from com.google.android.gms:play-services-maps:7.5.0:25:8
    android:required
        ADDED from com.google.android.gms:play-services-maps:7.5.0:26:8
android:uses-permission#android.permission.READ_EXTERNAL_STORAGE
IMPLIED from AndroidManifest.xml:2:1 reason: com.google.android.gms.maps requested WRITE_EXTERNAL_STORAGE
uses-permission#android.permission.GET_ACCOUNTS
ADDED from com.google.android.gms:play-services-wallet:7.5.0:21:5
    android:name
        ADDED from com.google.android.gms:play-services-wallet:7.5.0:21:22
uses-permission#android.permission.USE_CREDENTIALS
ADDED from com.google.android.gms:play-services-wallet:7.5.0:22:5
    android:name
        ADDED from com.google.android.gms:play-services-wallet:7.5.0:22:22
meta-data#com.google.android.gms.wallet.api.enabled
 ...<snips more lines away>
William
  • 20,150
  • 8
  • 49
  • 91
Angel Koh
  • 12,479
  • 7
  • 64
  • 91

2 Answers2

44

When you use

compile 'com.google.android.gms:play-services:7.5.0'

This implies you are using every feature of Google Play Services, including location services. If you only need a particular API, you should be using the selective APIs.

In the case of ads, you can use solely:

compile 'com.google.android.gms:play-services-ads:7.5.0'
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • 3
    ahhh. that fixed it. it's strange that the quick start guide calls us to use all the services instead of just the ads package. https://developers.google.com/admob/android/quick-start – Angel Koh Jun 05 '15 at 06:11
  • 1
    @AngelKoh - I've filed a bug with the Google documentation team to get the quick start guide updated. Thanks for pointing that out! – ianhanniballake Jun 05 '15 at 16:41
  • @ianhanniballake According to this blog post (http://googleadsdeveloper.blogspot.com/2014/12/announcing-v65-of-google-mobile-ads-sdk.html), there is a caveat that this method doesn't work if you initialize banner ads from XML – Nana Ghartey Jun 07 '15 at 00:05
  • 2
    @NanaGhartey - that was a limitation of version 6.5, not of 7.5. AFAIK, this limitation has been removed. – ianhanniballake Jun 07 '15 at 00:07
  • @ianhanniballake Thanks – Nana Ghartey Jun 07 '15 at 00:59
  • 3
    Note, [quick start guide](https://developers.google.com/admob/android/quick-start) is now updated to reference `play-services-ads` – ianhanniballake Jun 09 '15 at 18:49
  • 3
    play-services 7.5 is the first version that adds necessary permissions automatically, whereas in the past this was not done for you. – Wayne Piekarski Jun 22 '15 at 20:35
  • 1
    By the way even if you add them individually, as soon as you add `com.google.android.gms:play-services-wallet` it will auto require a bunch of permissions. – casolorz Jun 29 '15 at 16:20
  • I am making a game that uses leaderboards and achievements. I need to use the play-services-games and play-services-plus. I don't think I need anything else. But when I add these two compile lines in build.grade, I get a build error that says: `Error: more than one library with package name 'com.google.android.gms` – Mike James Johnson Aug 12 '15 at 00:34
  • @MikeJamesJohnson - that sounds like a different question - I'd post a new question including your `build.gradle` – ianhanniballake Aug 12 '15 at 00:43
  • @ianhanniballake I posted a new question. Check it out and let me know if you know what's going on with my problem. – Mike James Johnson Aug 12 '15 at 01:25
17

You can exclude those auto added permissions if your app feature doesn't require.

In my case i'm using Google wallet play service 8.3 which adds GET_ACCOUNTS and USE_CREDENTIALS . We don't required user to pick the google account for selecting google wallet.

<uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="remove"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" tools:node="remove" />

tools:node="remove" does the trick when creating the full manifest.

Look at the Full final AndroidManifest.xml at /build/intermediates/manifest/full/debug

Libin
  • 16,967
  • 7
  • 61
  • 83
  • This was more relevant to me since as of Play Services 8.3, `play-services-ads` dependency is bringing a `WAKE_LOCK` permission in. – Anthony Chuinard Jan 13 '16 at 22:16