java.lang.UnsupportedOperationException:Robolectric不支持API级别1

时间:2019-01-07 09:39:51

标签: java android junit4

我的gradle文件=

android {
    compileSdkVersion 28
    buildToolsVersion '25.0.2'
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

在下面的行中添加错误-

@RunWith(RobolectricTestRunner.class)
@Config(manifest="src/main/AndroidManifest.xml")

Error =
java.lang.UnsupportedOperationException: Robolectric does not support API level 1, sorry!

    at org.robolectric.SdkConfig.<init>(SdkConfig.java:23)
    at org.robolectric.RobolectricTestRunner.pickSdkVersion(RobolectricTestRunner.java:306)
    at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:282)
    at org.robolectric.RobolectricTestRunner.access$300(RobolectricTestRunner.java:37)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:183)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

1 个答案:

答案 0 :(得分:1)

您需要指定目标SDK版本。

例如,您可以为您认为的Class添加注释:

@Config(emulateSdk=18)

或者,您可以指定在AndroidManifest.xml中使用的版本。