Skip to content Skip to sidebar Skip to footer

Robolectric 3 Googleplayservicesnotavailableexception

I've just started to use Robolectric and wanted to know how to resolve Google Play Services. I'm using Robolectric 3 RC2, and my gradle is as follow : build.bradle compile 'com.sq

Solution 1:

I ran into this the other day.

Use:

testCompile 'org.robolectric:shadows-play-services:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'

And see this example:

publicclassTestBase {

    @BeforepublicvoidsetUp()throws Exception {
        // Turn off Google Analytics - Does not need to work anymorefinalShadowApplicationshadowApplication= Shadows.shadowOf(RuntimeEnvironment.application);
        shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");

        // Force success
       ShadowGooglePlayServicesUtil.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);
    }

    @AfterpublicvoidtearDown()throws Exception {

    }
}

public MyTestClass extendsTestBase {

}

Solution 2:

For folks trying to use GoogleApiAvailability with Robolectric...

gradle

dependencies {
  testApi 'org.robolectric:robolectric:3.6.1'
  testApi 'org.robolectric:shadows-playservices:3.6.1'
}

Code

publicclassTestBase {

    @BeforepublicvoidsetUp()throws Exception {
        finalShadowGoogleApiAvailabilityshadowGoogleApiAvailability= Shadows.shadowOf(GoogleApiAvailability.getInstance());
        shadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);
    }

    @AfterpublicvoidtearDown()throws Exception {
    }
}

public MyTestClass extendsTestBase {
}

Solution 3:

I don't think you can use Google play services with robolectric, you will need shadows.

Post a Comment for "Robolectric 3 Googleplayservicesnotavailableexception"