Skip to content

NoClassDefFoundError for PixelCopy$Request when using Robolectric 4.11 with SDK 30 #8577

@takahirom

Description

@takahirom

Description

With Robolectric 4.11 and SDK level 30, a NoClassDefFoundError is encountered when calling PixelCopy.request. This error does not occur when using SDK level 34 or when capturing screenshots via View.draw as shown in this pull request. I would prefer to use Robolectric's native mechanisms for screenshot capture in the Roborazzi library whenever possible.

Steps to Reproduce

  1. Configure a test to use Robolectric 4.11 with SDK level 30 or lower.
  2. Invoke PixelCopy.request.
  3. Observe that the NoClassDefFoundError for android/view/PixelCopy$Request occurs.

Example failure:

android/view/PixelCopy$Request
java.lang.NoClassDefFoundError: android/view/PixelCopy$Request
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)
	at java.base/java.lang.Class.getDeclaredMethod(Class.java:2673)
	at org.robolectric.internal.bytecode.ShadowWrangler.findShadowMethodDeclaredOnClass(ShadowWrangler.java:338)
	at org.robolectric.internal.bytecode.ShadowWrangler.findShadowMethod(ShadowWrangler.java:307)
	at org.robolectric.internal.bytecode.ShadowWrangler.pickShadowMethod(ShadowWrangler.java:284)
	at org.robolectric.internal.bytecode.ShadowWrangler.lambda$findShadowMethodHandle$0(ShadowWrangler.java:222)
	at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
	at org.robolectric.internal.bytecode.ShadowWrangler.findShadowMethodHandle(ShadowWrangler.java:216)
	at org.robolectric.internal.bytecode.RobolectricInternals.findShadowMethodHandle(RobolectricInternals.java:36)
	at org.robolectric.internal.bytecode.InvokeDynamicSupport.bindCallSite(InvokeDynamicSupport.java:161)
	at org.robolectric.internal.bytecode.InvokeDynamicSupport.lambda$bootstrapStatic$2(InvokeDynamicSupport.java:104)
	at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
	at org.robolectric.internal.bytecode.InvokeDynamicSupport.bootstrapStatic(InvokeDynamicSupport.java:98)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:109)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
	at android.view.PixelCopy.request(PixelCopy.java)
	at com.github.takahirom.roborazzi.ViewScreenshotKt.generateBitmapFromPixelCopy(ViewScreenshot.kt:201)
	at com.github.takahirom.roborazzi.ViewScreenshotKt.generateBitmapFromPixelCopy(ViewScreenshot.kt:184)
	at com.github.takahirom.roborazzi.ViewScreenshotKt.generateBitmap(ViewScreenshot.kt:122)

Robolectric & Android Version

Robolectric version: 4.11
Android SDK tested: 30

Link to a public git repo demonstrating the problem:

https://github.com/takahirom/roborazzi/actions/runs/6686917489/job/18166895974
https://github.com/takahirom/roborazzi/blob/14a62c6c069422089b71f25a0f7f01310966b6f8/include-build/roborazzi-core/src/androidMain/kotlin/com/github/takahirom/roborazzi/ViewScreenshot.kt#L200-L206

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions