2

AFter reading the following question: Why are permissions being automatically added to my AndroidManifest when including Google Play Services library I realized that I need to change my compiled items in build.gradle.

currently I have compile 'com.google.android.gms:play-services:7.5.0' but this is adding so many unnecessary permissions like location, permission to read and write to SD card, full network access, view network connections,etc. I am only using Google Play Services for leaderboards and achievements in my game. So I don't think I need any of those permissions on my app.

So what should I compile instead? I have to list the specific services, but I am unable to find a list of services so that I can pick and choose.

It would be something like:

compile 'com.google.android.gms:play-services-achievements7.5.0'
compile 'com.google.android.gms:play-services-leaderboards7.5.0'

I want as few permissions as possible for a game that only uses these services on Google Play.

I also have these permissions declared in my Manifest:

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />

Can anyone provide me with the proper services to compile?

UPDATE Here is my build.gradle file:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "mjj.fling"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

`dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services-games:7.5.0'
    compile project(':BaseGameUtils')

    apply plugin: 'com.google.gms.google-services'`

}


FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task ':app:processDebugResources'.

    Error: more than one library with package name 'com.google.android.gms' You can temporarily disable this error with android.enforceUniquePackageName=false However, this is temporary and will be enforced in 1.0

And here is my error I get when I rebuild project.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Community
  • 1
  • 1
Mike James Johnson
  • 724
  • 2
  • 8
  • 29

1 Answers1

3

Checkout https://developers.google.com/android/guides/setup for information from Google how to set up Play Services. Especially checkout the subsection titled Selectively compiling APIs into your executable. It shows you how to breakdown which services to compile in. You'll probably want to use just the games one:

com.google.android.gms:play-services-games:7.5.0

In addition to using fewer permissions, it'll also reduce your APK size and method count, both good things to do anyways instead of pulling in the whole Play Services library.

zerobasedindex
  • 1,291
  • 9
  • 5
  • Much appreciated. This is what I needed – Mike James Johnson Aug 12 '15 at 00:36
  • Ok I just got the chance to try it out. I updated the question with my build.gradle file and error. Not sure what is going on... – Mike James Johnson Aug 12 '15 at 01:24
  • Your apply plugin should be outside of the dependencies list but up with the other apply at the top of your file. Also not sure if you need it at all TBH, but not entirely sure. I don't think we use it in our app. – zerobasedindex Aug 12 '15 at 01:26
  • So I don't need to put this in as a dependency if I want to connect to Google Play and use their leaderboards / achievements system?! – Mike James Johnson Aug 12 '15 at 01:35
  • Ok i completely got rid of all of my manifest permissions (except vibrate one) as well as the gms:playservices- permissions, and the game still works and I am still able to connect to google play and update leaderboards /achievements. I even removed the 'apply gms.google-services` and it still works!! I am afraid I am removing too much haha.. does this sound right? – Mike James Johnson Aug 12 '15 at 01:48
  • 1
    Hey, if it works, it works. I bet your `BaseGameUtils` compile in your dependencies is helping you bring stuff in that you were including manually before. It looks to be a project used in Googles examples. Looks like it if you're pulling it from here: https://github.com/playgameservices/android-basic-samples/blob/master/BasicSamples/libraries/BaseGameUtils/build.gradle – zerobasedindex Aug 12 '15 at 03:35
  • The *TypeANumber* sample project which uses leaderboards and achievements does not use any "uses-permission" tag at all in its manifest file. – Jonny Aug 24 '15 at 01:02