Robolectric does not support API level 28

Second edit: This has graduated from snapshot and is now available with

testImplementation 'org.robolectric:robolectric:4.0-beta-1'

i.e. you no longer need the maven snapshot line.


Edit: This is now fixed and available in the snapshot build. In your gradle build file (app level) add

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

and

dependencies {
    testImplementation 'org.robolectric:robolectric:4.0-alpha-3-SNAPSHOT'
}

Now that this issue is updated with info from a contributor it seems like there will be a new 4.0 alpha release that fixes the issue within this week.


To complete Algar's answer, you can bypass temporarily this error (meanwhile Robolectric fix this issue) by annotating your test class like that :

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.O_MR1])
class YourUnitTests {

...

}

It will force Robolectric using Android API 27.