Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.google.android.gms:play-services-ads:7.8.0 AudioManager NullPointerException #1992

Closed
jaredsburrows opened this issue Aug 15, 2015 · 5 comments · Fixed by #2033
Closed

Comments

@jaredsburrows
Copy link
Contributor

I have filed this issue here: https://code.google.com/p/android/issues/detail?id=182868. I do not think this is really a Robolectric issue but I wanted this to be indexed by Google so we can start documenting support here.

For now, I have gone back to 7.5.0.

I recently received this exception when upgrading from 7.5.0 to 7.8.0. The tests worked fine before.

What steps will reproduce the problem?

gradle clean assembleDebug testDebug 

Exception running Robolectric:

<>.activity.MainActivityTest > activity_create_start_destroy_visible FAILED
java.lang.NullPointerException
at android.media.AudioManager.getMode(AudioManager.java:1674)
at com.google.android.gms.internal.zzgr$zza.zzA(Unknown Source)
at com.google.android.gms.internal.zzgr$zza.(Unknown Source)
at com.google.android.gms.internal.zzgs.zzD(Unknown Source)
at com.google.android.gms.internal.zzbz.(Unknown Source)
at com.google.android.gms.internal.zzhl.zzgk(Unknown Source)
at com.google.android.gms.internal.zzhl.zzb(Unknown Source)
at com.google.android.gms.ads.internal.zza.(Unknown Source)
at com.google.android.gms.ads.internal.zzb.(Unknown Source)
at com.google.android.gms.ads.internal.zzb.(Unknown Source)
at com.google.android.gms.ads.internal.zzc.(Unknown Source)
at com.google.android.gms.ads.internal.zzf.(Unknown Source)
at com.google.android.gms.ads.internal.client.zze.zza(Unknown Source)
at com.google.android.gms.ads.internal.client.zzy.zzcT(Unknown Source)
at com.google.android.gms.ads.internal.client.zzy.zzcS(Unknown Source)
at com.google.android.gms.ads.internal.client.zzy.zza(Unknown Source)
at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
at <>.ads.Banner.loadAd(Banner.java:183)
at <>.ads.Banner.access$300(Banner.java:21)
at <>.ads.Banner$2.run(Banner.java:44)
at org.robolectric.util.Scheduler$ScheduledRunnable.run(Scheduler.java:269)
at org.robolectric.util.Scheduler.runOneTask(Scheduler.java:179)
at org.robolectric.util.Scheduler.advanceTo(Scheduler.java:160)
at org.robolectric.util.Scheduler.advanceBy(Scheduler.java:143)
at org.robolectric.util.Scheduler.unPause(Scheduler.java:54)
at org.robolectric.shadows.ShadowLooper.unPause(ShadowLooper.java:266)
at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:306)
at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:45)
at org.robolectric.util.ActivityController.create(ActivityController.java:118)
at org.robolectric.util.ActivityController.create(ActivityController.java:129)
at <>.activity.MainActivityTest.setUp(MainActivityTest.java:49)

Example Test:

@Test
public void activity_create_start_destroy_visible() {
    final MainActivity activity = Robolectric.buildActivity(MainActivity.class).create().start().destroy().get();
    MatcherAssert.assertThat(activity, Matchers.not(Matchers.nullValue()));
}
@hidroh
Copy link
Contributor

hidroh commented Aug 15, 2015

Encountered the same problem, which forces us to revert back to 7.5.0 for now.

@jaredsburrows
Copy link
Contributor Author

@hidroh! Thanks for response and the confirmation. I wanted to document this.

@erd
Copy link
Member

erd commented Aug 18, 2015

It looks like this just needs a shadow for AudioManager.getMode. The real method makes an RPC call, which we don't intercept.

@niccs
Copy link

niccs commented Sep 23, 2015

I also encountered the same issue, but I am not using play services...(Robolectric 3.0)

java.lang.NullPointerException
at android.media.AudioManager.getMode(AudioManager.java:1674)
at org.iilab.pb.trigger.HardwareTriggerReceiver.isCallActive(HardwareTriggerReceiver.java:72)
at org.iilab.pb.trigger.HardwareTriggerReceiverTest.shouldNotProcessAnyThingForIntentsOtherThanScreenOnAndOff(HardwareTriggerReceiverTest.java:85)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:251)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:188)
at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:54)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:152)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

@jaredsburrows
Copy link
Contributor Author

For those waiting for 3.1 release, setup your testCompile configuration like this(this is for build with GPS 7.8.0+ and testing against 7.5.0):

compile ('com.google.android.gms:play-services-ads:7.5.0') { // robolectric 3.1 needs to be released
    exclude module: 'support-v4'
    exclude module: 'support-annotations'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants