facebook / screenshot-tests-for-android

Generate fast deterministic screenshots during Android instrumentation tests
http://facebook.github.io/screenshot-tests-for-android
Apache License 2.0
1.74k stars 229 forks source link

Firebase NoSuchMethodException #260

Open sanginovs opened 4 years ago

sanginovs commented 4 years ago

Hi,

I've been trying to run screenshot tests on Firebase test lab however i am running into this error:

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at com.facebook.testing.screenshot.internal.ScreenshotImpl.runCallableOnUiThread(ScreenshotImpl.java:345) at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:166) at com.facebook.testing.screenshot.internal.ScreenshotImpl.record(ScreenshotImpl.java:270) at com.facebook.testing.screenshot.internal.RecordBuilderImpl.record(RecordBuilderImpl.java:152) at com.nextdoor.blocksapp.rows.RowScreenshotTest.testAlertBanner(RowScreenshotTest.kt:36) at java.lang.reflect.Method.invoke(Native Method) 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.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 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.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) 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.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56) at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145) Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at com.facebook.testing.screenshot.WindowAttachment.generateAttachInfo(WindowAttachment.java:230) at com.facebook.testing.screenshot.WindowAttachment.dispatchAttach(WindowAttachment.java:89) at com.facebook.testing.screenshot.internal.ScreenshotImpl.storeBitmap(ScreenshotImpl.java:182) at com.facebook.testing.screenshot.internal.ScreenshotImpl.access$000(ScreenshotImpl.java:50) at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:170) at com.facebook.testing.screenshot.internal.ScreenshotImpl$2.call(ScreenshotImpl.java:167) at com.facebook.testing.screenshot.internal.ScreenshotImpl$3.run(ScreenshotImpl.java:327) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, class android.view.Display] at java.lang.Class.getConstructor0(Class.java:2327) at java.lang.Class.getConstructor(Class.java:1725) at com.facebook.testing.screenshot.WindowAttachment.generateAttachInfo(WindowAttachment.java:163) ... 13 more

Someone had similar issue before based on this thread. The solution mentioned in that thread by @xiphirx is to run these commands: adb shell settings put global hidden_api_policy_p_apps 1 adb shell settings put global hidden_api_policy_pre_p_apps 1 adb shell settings put global hidden_api_policy 1 // this is for Q+

However, i don't have access to adb on firebase. Was anyone able to bypass this issue and get screenshot tests working on Firebase Test Lab?

I think this problem occurs for API >=28 because when i test it with Galaxy S7 edge, API Level 23 on Firebase Test Lab, it works.

xiphirx commented 3 years ago

Yeah this is because of restrictions on hidden API access / reflection. Unfortunately I don't have much of a solution for you outside of those adb commands :(

I think at some point it would make sense to re-evaluate and see if all of the reflection is necessary in the library.