RikkaApps / HiddenApiRefinePlugin

A Gradle plugin that improves the experience when developing Android apps, especially system tools, that use hidden APIs.
MIT License
272 stars 17 forks source link

[BUG] Robolectric tests are failing in 4.1.0 and later #20

Open MuntashirAkon opened 1 year ago

MuntashirAkon commented 1 year ago

After updating to 4.1.0, all the Roboletric tests are failing with the following error:

SHA-256 digest error for org/conscrypt/OpenSSLProvider.class
java.lang.SecurityException: SHA-256 digest error for org/conscrypt/OpenSSLProvider.class
    at java.base/sun.security.util.ManifestEntryVerifier.verify(ManifestEntryVerifier.java:223)
    at java.base/java.util.jar.JarVerifier.processEntry(JarVerifier.java:243)
    at java.base/java.util.jar.JarVerifier.update(JarVerifier.java:230)
    at java.base/java.util.jar.JarVerifier$VerifierStream.read(JarVerifier.java:475)
    at java.base/jdk.internal.loader.Resource.getBytes(Resource.java:126)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:818)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at org.robolectric.internal.bytecode.SandboxClassLoader.loadClass(SandboxClassLoader.java:135)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3215)
    at java.base/java.lang.Class.getConstructors(Class.java:1957)
    at org.robolectric.util.inject.Injector.findConstructor(Injector.java:262)
    at org.robolectric.util.inject.Injector.inject(Injector.java:243)
    at org.robolectric.util.inject.Injector.lambda$new$0(Injector.java:126)
    at org.robolectric.util.inject.Injector$MemoizingProvider.get(Injector.java:498)
    at org.robolectric.util.inject.Injector.getInstanceInternal(Injector.java:224)
    at org.robolectric.util.inject.Injector.getInstance(Injector.java:208)
    at org.robolectric.util.inject.Injector.getInstance(Injector.java:202)
    at org.robolectric.internal.AndroidSandbox.lambda$new$0(AndroidSandbox.java:60)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)

Related issue: #5

MuntashirAkon commented 1 year ago

It seems Robolectric is failing because it's classes are repacked by this plugin. If there is a way to bypass this, it should run just fine.

utzcoz commented 1 year ago

@MuntashirAkon What about trying 4.3.0, looks like it introduces a new change to restrict instrumentation scope when applying it as a library: https://github.com/RikkaApps/HiddenApiRefinePlugin/commit/484a2856024d0fec24fe1c8f153857b712d9ab7f. cc @Kyle-Falconer.

MuntashirAkon commented 1 year ago

Already tested, and it was not working. Transformation were still happening:

...
> Task :app:generateDebugUnitTestConfig
> Task :app:transformDebugClassesWithAsm
> Task :app:bundleDebugClassesToRuntimeJar
> Task :app:transformDebugUnitTestClassesWithAsm
> Task :app:testDebugUnitTest
...

The last working version is still v4.0.0.

utzcoz commented 1 year ago

@MuntashirAkon What about disabling conscrypt mode with Config? See https://github.com/robolectric/robolectric/issues/8165. Also trying to removing conscrypt from explicit dependencies.

Kyle-Falconer commented 1 year ago

Yes, I tried disabling conscrypt. See my comment in the other issue.

Svyattoy7 commented 1 month ago

After updating to 4.1.0, all the Roboletric tests are failing with the following error:

SHA-256 digest error for org/conscrypt/OpenSSLProvider.class
java.lang.SecurityException: SHA-256 digest error for org/conscrypt/OpenSSLProvider.class
  at java.base/sun.security.util.ManifestEntryVerifier.verify(ManifestEntryVerifier.java:223)
  at java.base/java.util.jar.JarVerifier.processEntry(JarVerifier.java:243)
  at java.base/java.util.jar.JarVerifier.update(JarVerifier.java:230)
  at java.base/java.util.jar.JarVerifier$VerifierStream.read(JarVerifier.java:475)
  at java.base/jdk.internal.loader.Resource.getBytes(Resource.java:126)
  at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:818)
  at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
  at org.robolectric.internal.bytecode.SandboxClassLoader.loadClass(SandboxClassLoader.java:135)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
  at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
  at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3215)
  at java.base/java.lang.Class.getConstructors(Class.java:1957)
  at org.robolectric.util.inject.Injector.findConstructor(Injector.java:262)
  at org.robolectric.util.inject.Injector.inject(Injector.java:243)
  at org.robolectric.util.inject.Injector.lambda$new$0(Injector.java:126)
  at org.robolectric.util.inject.Injector$MemoizingProvider.get(Injector.java:498)
  at org.robolectric.util.inject.Injector.getInstanceInternal(Injector.java:224)
  at org.robolectric.util.inject.Injector.getInstance(Injector.java:208)
  at org.robolectric.util.inject.Injector.getInstance(Injector.java:202)
  at org.robolectric.internal.AndroidSandbox.lambda$new$0(AndroidSandbox.java:60)
  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
  at java.base/java.lang.Thread.run(Thread.java:832)

Related issue: #5

t-beckmann commented 1 week ago

I can confirm this is an issue. Version 4.4.0 does not work with robolectric: digest error at OpenSSLProvider. I downgraded to 4.0.0.

I am a new user of your tool. Thank you for the amazing work you did! Well done and valuable!