java.lang.NoClassDefFoundError: android/content/ContentResolver
kuFEAR opened this issue · comments
Description
java.lang.NoClassDefFoundError: android/content/ContentResolver
Steps to Reproduce
Any RobolectricTest with ApplicationProvider.getApplicationContext() call
Robolectric & Android Version
4.4-beta-1, android 29, openjdk14
Link to a public git repo demonstrating the problem:
none
java.lang.NoClassDefFoundError: android/content/ContentResolver
at org.robolectric.Shadows.reset(Shadows.java:2317)
at org.robolectric.android.internal.AndroidTestEnvironment.resetState(AndroidTestEnvironment.java:518)
at org.robolectric.RobolectricTestRunner.lambda$finallyAfterTest$0(RobolectricTestRunner.java:349)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:75)
at org.robolectric.RobolectricTestRunner.finallyAfterTest(RobolectricTestRunner.java:347)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:272)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
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)
Caused by: java.lang.ClassNotFoundException: couldn't load android.content.ContentResolver
at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:147)
at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$loadClass$0(SandboxClassLoader.java:115)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
at org.robolectric.internal.bytecode.SandboxClassLoader.loadClass(SandboxClassLoader.java:115)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 11 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 58
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:184)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:166)
at org.objectweb.asm.ClassReader.<init>(ClassReader.java:152)
at org.robolectric.internal.bytecode.ClassNodeProvider.createClassNode(ClassNodeProvider.java:24)
at org.robolectric.internal.bytecode.ClassNodeProvider.getClassNode(ClassNodeProvider.java:16)
at org.robolectric.internal.bytecode.InstrumentingClassWriter.typeInfo(InstrumentingClassWriter.java:115)
at org.robolectric.internal.bytecode.InstrumentingClassWriter.typeImplements(InstrumentingClassWriter.java:109)
at org.robolectric.internal.bytecode.InstrumentingClassWriter.getCommonSuperClass(InstrumentingClassWriter.java:50)
at org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1198)
at org.objectweb.asm.Frame.merge(Frame.java:1294)
at org.objectweb.asm.Frame.merge(Frame.java:1175)
at org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1617)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1553)
at org.objectweb.asm.MethodVisitor.visitMaxs(MethodVisitor.java:768)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:767)
at org.objectweb.asm.tree.MethodNode.accept(MethodNode.java:647)
at org.objectweb.asm.tree.ClassNode.accept(ClassNode.java:408)
at org.robolectric.internal.bytecode.ClassInstrumentor.instrumentToBytes(ClassInstrumentor.java:80)
at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$maybeInstrumentClass$2(SandboxClassLoader.java:139)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:53)
at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:138)
... 15 more
package sample
import android.net.Uri
import androidx.test.core.app.ApplicationProvider
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
...
@RunWith(RobolectricTestRunner::class)
class AdviserBuyRouteTest : BaseRouteTest() {
private val routeParams = RouteParams(
Uri.parse("${DeeplinkHelper.SCHEME}://${DeeplinkHelper.AUTHORITY}/invest/recommendations/buy/ticker"),
null
)
private val route = AdviserBuyRoute(CatalogRoute(routeManager), routeManager)
@Test
fun testRouteIntents() {
route.start(ApplicationProvider.getApplicationContext<App>(), routeParams)
.runTest {
assertIntents(
MainActivity::class,
WidgetPortfolioBuyActivity::class
)
}
}
@Test
fun testRouteBundle() {
route.start(ApplicationProvider.getApplicationContext<App>(), routeParams)
.runTest {
assertExtras<MainActivity> {
assertArgument(MainActivity.EXTRA_SELECTED_TAB, BottomNavigationController.Tab.TAB_CATALOG)
assertArgument(MainActivity.EXTRA_SELECTED_INNER_TAB, -1)
}
assertExtras<WidgetPortfolioBuyActivity> {
assertArgument(WidgetPortfolioBuyActivity.EXTRA_WIDGET_ID, "ticker")
}
}
}
}
Robolectric doesn't support running on JDK 14 at the moment. Specifically, the asm dependency doesn't seem to support JDK 14. You should be able to use 13 and below.