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:

public class TestBase {

    @Before
    public void setUp() throws Exception {
        // Turn off Google Analytics - Does not need to work anymore
        final ShadowApplication shadowApplication = Shadows.shadowOf(RuntimeEnvironment.application);
        shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");

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

    @After
    public void tearDown() throws Exception {

    }
}

public MyTestClass extends TestBase {

}

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

public class TestBase {

    @Before
    public void setUp() throws Exception {
        final ShadowGoogleApiAvailability shadowGoogleApiAvailability
                = Shadows.shadowOf(GoogleApiAvailability.getInstance());
        shadowGoogleApiAvailability.setIsGooglePlayServicesAvailable(ConnectionResult.SUCCESS);
    }

    @After
    public void tearDown() throws Exception {
    }
}

public MyTestClass extends TestBase {
}

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"