Skip to content

Instantly share code, notes, and snippets.

@plackemacher
plackemacher / BaseTest.java
Created September 30, 2015 16:25
Robolectric Activity Leak Fix
@SuppressLint("NewApi")
@After
public void resetWindowManager() {
Class clazz = ReflectionHelpers.loadClass(getClass().getClassLoader(), "android.view.WindowManagerGlobal");
Object instance = ReflectionHelpers.callStaticMethod(clazz, "getInstance");
// We essentially duplicate what's in {@link WindowManagerGlobal#closeAll} with what's below.
// The closeAll method has a bit of a bug where it's iterating through the "roots" but
// bases the number of objects to iterate through by the number of "views." This can result in
// an {@link java.lang.IndexOutOfBoundsException} being thrown.

Keybase proof

I hereby claim:

  • I am plackemacher on github.
  • I am plackemacher (https://keybase.io/plackemacher) on keybase.
  • I have a public key whose fingerprint is 8BEB 7688 A0AA D801 5D10 B7FE 6D77 43DD 782C C4CE

To claim this, I am signing this object:

@plackemacher
plackemacher / gist:753c72de590d4cf06a5e
Created June 27, 2014 13:52
TestFairy Gradle exception in Android Studio
Caused by: org.gradle.api.GradleException: Could not locate zipalign, please validate 'buildToolsVersion' settings
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)