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

Ensure ShadowActivity can work with project targetSdk less than S #7254

Merged
merged 1 commit into from Apr 25, 2022

Conversation

utzcoz
Copy link
Member

@utzcoz utzcoz commented Apr 17, 2022

Ensure ShadowActivity can work with project targetSdk less than S.

@utzcoz utzcoz requested a review from hoisie April 17, 2022 12:30
@utzcoz
Copy link
Member Author

utzcoz commented Apr 17, 2022

Hi @hoisie, this PR can reproduce SplashScreen compatibility problem when launching Activity with latest Robolectric master branch if targetSdk is less than 31.

This is exception stacktrace when running it on my laptop:

java.lang.NoClassDefFoundError: android/window/SplashScreen
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
	at java.base/java.lang.Class.getDeclaredMethod(Class.java:2473)
	at org.robolectric.internal.bytecode.ShadowWrangler.findShadowMethodDeclaredOnClass(ShadowWrangler.java:385)
	at org.robolectric.internal.bytecode.ShadowWrangler.findShadowMethod(ShadowWrangler.java:354)
	at org.robolectric.internal.bytecode.ShadowWrangler.pickShadowMethod(ShadowWrangler.java:331)
	at org.robolectric.internal.bytecode.ShadowWrangler.classInitializing(ShadowWrangler.java:190)
	at org.robolectric.internal.bytecode.RobolectricInternals.classInitializing(RobolectricInternals.java:21)
	at android.app.Activity.<clinit>(Activity.java)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at org.robolectric.android.internal.RoboMonitoringInstrumentation.startActivitySyncInternal(RoboMonitoringInstrumentation.java:92)
	at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:33)
	at org.robolectric.android.internal.LocalActivityInvoker.startActivity(LocalActivityInvoker.java:38)
	at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:265)
	at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:195)
	at org.robolectric.integration.compat.target29.Target29CompatibilityTest.Initialize Activity succeed(Target29CompatibilityTest.kt:32)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:591)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:274)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:88)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: android.window.SplashScreen
	at org.robolectric.internal.bytecode.SandboxClassLoader.getByteCode(SandboxClassLoader.java:189)
	at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:147)
	at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$loadClass$0(SandboxClassLoader.java:133)
	at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
	at org.robolectric.internal.bytecode.SandboxClassLoader.loadClass(SandboxClassLoader.java:133)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 33 more

This CL also adds Activity launch compatibility test with targetSdk 29
compatibility integration tests.

Signed-off-by: utzcoz <utzcoz@outlook.com>
@utzcoz utzcoz force-pushed the SplashScreen-compatibility branch from 93d706f to 8a4a63e Compare April 17, 2022 12:55
@utzcoz utzcoz changed the title Add Activity launch compatibility test with targetSdk 29 Ensure ShadowActivity can work with project targetSdk less than S Apr 17, 2022
@utzcoz
Copy link
Member Author

utzcoz commented Apr 17, 2022

It needs project of #7181 to provide more proper solution.

@utzcoz
Copy link
Member Author

utzcoz commented Apr 17, 2022

@hoisie I sent a new commit to fix this problem with looseSignature.

@utzcoz
Copy link
Member Author

utzcoz commented Apr 19, 2022

Hi @hoisie , could you help to take look at this PR? I hope it can be merged before 4.8 released. Thanks.

@utzcoz
Copy link
Member Author

utzcoz commented Apr 25, 2022

Hi @hoisie , could you help to take look at this PR? I hope it can be merged before 4.8 released. Thanks.

Friendly ping, @hoisie could you help to take look at this PR before 4.8 release? Thanks.

Copy link
Contributor

@hoisie hoisie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! This is exactly the type of issue I'd like to automatically catch using RAP (Robolectric annotation processor). It is the gsoc project that I had in mind.

@utzcoz
Copy link
Member Author

utzcoz commented Apr 25, 2022

Nice, thanks! This is exactly the type of issue I'd like to automatically catch using RAP (Robolectric annotation processor). It is the gsoc project that I had in mind.

Yup. This is important for next release. But we can improve this problem at related GSoC project.

@utzcoz utzcoz merged commit a0651a2 into robolectric:master Apr 25, 2022
@utzcoz utzcoz deleted the SplashScreen-compatibility branch April 25, 2022 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants