Error:
java.lang.IllegalArgumentException: failed to configure : Package targetSdkVersion=30 > maxSdkVersion=29
at org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:247) at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:534) at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:400) at androidx.test.ext.junit.runners.AndroidJUnit4.getDescription(AndroidJUnit4.java:149) at org.junit.runners.model.RunnerBuilder.configureRunner(RunnerBuilder.java:81) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:72) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70) at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28) at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53) Caused by: java.lang.IllegalArgumentException: Package targetSdkVersion=30 > maxSdkVersion=29 at org.robolectric.plugins.DefaultSdkPicker.configuredSdks(DefaultSdkPicker.java:118) at org.robolectric.plugins.DefaultSdkPicker.selectSdks(DefaultSdkPicker.java:69) at org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:213) ... 13 more
How to fix this issue?
Found this post with the same issue, with a different error message.
This answer helped me to solve the issue.
Posting the same here.
Create a robolectric.properties
file inside the app/src/test/resources
directory with the following line:
sdk=29
This will force Robolectric to use API 29 instead of 30.
Note: Robolectric supports up to SDK 29 now (As on Sep 4th, 2020).
There are two ways to achieve this:
Creating prop file (mentioned in Abhimanyu's answer)
robolectric.properties
in app/src/test/resources
sdk=29
in itLimit your test target SDK using Config
annotation. This makes you consider different configs for different tests or avoid creating extra config files.
@Config(sdk = [29])
class Test {
// ...
}
Both the above answers work fine, but the latest version of robolectric supports android sdk 30.
So just upgrade the robolectric dependency to fix the issue.
At the time of writing, the latest version was 4.5.1.
For the up to date version please refer the official github site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With