2

I am using play services on Android to request periodic user locations. For that purpose, I added the following dependency on my app/build.gradle

compile "com.google.android.gms:play-services-location:11.0.0"

In physical devices it works pretty well. However, on emulators it does not work and it prompts to update play services.

enter image description here

I have tried different solutions according to following questions

How to update Google Play Services for Android Studio 2.2 emulators?

How to update Google Play Services on the emulator in Android Studio

https://android.stackexchange.com/questions/176578/how-to-use-google-maps-android-api-by-google-play-services-11-on-an-emulator-wit (it was marked as off-the-topic, but here the same problem is described)

I tried creating a new emulator with an x86_64 image with Google APIs, but that does not solve the problem.

enter image description here

I have also checked for updates on Android Studio (I have version 2.3.3) but it says the IDE is up to date.

How can I run Google Play Services V11.0.0 and above on emulators? Any help with this issue will be appreciated

EDIT:

Here is my app/build.gradle file

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        // These docs use an open ended version so that our plugin
        // can be updated quickly in response to Android tooling updates

        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
        classpath 'io.fabric.tools:gradle:1.22.0'
        classpath 'me.tatarka:gradle-retrolambda:3.6.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'

repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "xxxxxxxxxxxxxxxx"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        manifestPlaceholders = [fabric_io_id: "$System.env.FABRIC_KEY"]
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true
    }

    signingConfigs {
        release {
            try {
                storeFile new File(STORE_FILE)
                storePassword STORE_PASSWORD
                keyAlias KEY_ALIAS
                keyPassword KEY_PASSWORD
            } catch (ex) {
                throw new InvalidUserDataException("Signing configuration not found")
            }
        }
    }

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    productFlavors {
        development {
            versionNameSuffix "-dev"
            manifestPlaceholders = [
                    appName: "xxxx"
            ]
        }

        production {
            manifestPlaceholders = [
                    appName: "xxxxxxxxxxxxx"
            ]
        }
    }
    variantFilter { variant ->
        def names = variant.flavors*.name

        if ((names.contains("alpha") || names.contains("qatesting") || names.contains("sandbox") || names.contains("production"))
                && variant.buildType.name == "debug") {
            variant.ignore = true
        }
        if (names.contains("development") && variant.buildType.name == "release") {
            variant.ignore = true
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = new File(
                    output.outputFile.parent,
                    output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/rxjava.properties'
    }
}

ext {
    supportLibraryVersion = '25.3.1'
    butterKnifeVersion = '8.5.1'
    leakCanaryVersion = '1.5.1'
    daggerVersion = '2.10'
    rxAndroidVersion = '2.0.1'
    rxJavaVersion = '2.1.0'
    timberVersion = '4.5.1'
    jUnitVersion = '4.12'
    mockitoVersion = '1.10.19'
    testRunnerVersion = '0.5'
    powerMockVersion = '1.6.2'
    crashlyticsVersion = '2.6.8'
    guavaVersion = '19.0'
    googlePlayServicesVersion = '11.0.1'
    contraintLayoutVersion = '1.0.2'
    awsCognitoVersion = '2.4.3'
    espressoVersion = '2.2.2'
    retrofitVersion = '2.3.0'
    jacksonConverterVersion = '2.1.0'
    okHttpLoggingInterceptorVersion = '3.2.0'
    firebaseJobDispatcherVersion = '0.6.0'
    apacheCommonsVersion = '3.6'
    multiDexVersion = '1.0.1'
}

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

    compile "com.android.support:appcompat-v7:$supportLibraryVersion"
    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support:support-v4:$supportLibraryVersion"

    /* Multidex */
    compile "com.android.support:multidex:$multiDexVersion"

    /* Views injection - Butterknife */
    compile "com.jakewharton:butterknife:$butterKnifeVersion"
    annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"

    /* Memory leaks detection - LeakCanary */
    debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
    releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
    testCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"

    /* Dependency Injection - Dagger*/
    compile "com.google.dagger:dagger:$daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

    /* Rx Android - Rx Java */
    compile "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
    compile "io.reactivex.rxjava2:rxjava:$rxJavaVersion"

    /* Application Logger - Timber*/
    compile "com.jakewharton.timber:timber:$timberVersion"

    /* Crashlytics - crash reporting */
    compile("com.crashlytics.sdk.android:crashlytics:$crashlyticsVersion@aar") {
        transitive = true;
    }

    /* Google analytics */
    compile "com.android.support.constraint:constraint-layout:$contraintLayoutVersion"
    compile "com.google.android.gms:play-services-analytics:$googlePlayServicesVersion"
    compile "com.google.guava:guava:$guavaVersion"
    compile "com.android.support:support-v4:$supportLibraryVersion"

    /* Google play location services */
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"

    /* Amazon cognito */
    compile "com.amazonaws:aws-android-sdk-cognitoidentityprovider:$awsCognitoVersion"

    /* Retrofit - API rest access*/
    compile "com.squareup.retrofit2:retrofit:$retrofitVersion"

    /* Retrofit JSON converter with Jackson */
    compile "com.squareup.retrofit2:converter-jackson:$jacksonConverterVersion"

    /* Firebase job dispatcher */
    compile "com.firebase:firebase-jobdispatcher:$firebaseJobDispatcherVersion"

    /* Mapbox */
    compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar') {
        transitive = true
    }

    compile "com.google.android.gms:play-services-places:$googlePlayServicesVersion"

    /* Apache commons */
    compile "org.apache.commons:commons-lang3:$apacheCommonsVersion"

    /* Android testing */
    testCompile "junit:junit:$jUnitVersion"
    testCompile "org.mockito:mockito-core:$mockitoVersion"
    androidTestCompile("com.android.support.test.espresso:espresso-core:$espressoVersion", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestCompile "com.android.support.test:runner:$testRunnerVersion"
    androidTestCompile "com.android.support:support-annotations:$supportLibraryVersion"
    testCompile "org.powermock:powermock-api-mockito:$powerMockVersion"
    testCompile "org.powermock:powermock-module-junit4-rule-agent:$powerMockVersion"
    testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
    testCompile "org.powermock:powermock-module-junit4:$powerMockVersion"
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    compile 'com.fasterxml.jackson.core:jackson-core:2.8.8'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.8'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.8'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:25.3.1'
}
Nicolás Arias
  • 1,053
  • 1
  • 12
  • 29

1 Answers1

0

Google released emulator images featuring the whole Google Play Store. Those should be able to get the most recent version of the PlayServices via the Play Store.

EDIT: Virtual Device Manager - Screenshot

  • How can I do this? When I click update nothing happens and I can see in the logs that there is no intent to handle the request. – Nicolás Arias Jun 21 '17 at 15:19
  • What is failing exactly? Can you install and run the Play Store enabled image? Is the Play Store working? Can you load any apps from the Play Store? – Hauke Radtki Jun 21 '17 at 15:32
  • I am using the Nexus 5 and Nexus 5X shown in your pictures, but that does not work. I Just realized there are emulator images with Play Store support but only for Android N and O. I created a couple of virtual devices with the N image, but when running the app the device appears indefinitely offline and at the end it does not run. Emulators created with different images just do not have Play Store installed on them. Anyway, I would like to test my app on devices starting on 4.4 version. – Nicolás Arias Jun 21 '17 at 17:20
  • You could try Genymotion. https://stackoverflow.com/questions/20121883/how-to-install-google-play-services-in-a-genymotion-vm-with-no-drag-and-drop-su – Hauke Radtki Jun 22 '17 at 12:01