Robolectric does not support API level 28

旧时模样 提交于 2020-01-13 07:53:08

问题


Although this question has been answered for previous versions in other threads, none of the answers seems to work for me with api 28 right now so..

All Robolectric tests worked fine when on api 27. Now when my app api target is 28 they all fail.

I have

@Config(constants = BuildConfig::class, sdk = [Build.VERSION_CODES.P])

on my test class.

Diving into Robolectrics internal SdkConfig.java it looks like they add support for api 28:

addSdk(Build.VERSION_CODES.P, "P", "4651975", "P");

But when evaluating that line of code in the debugger, Build.VERSION_CODES.P evaluates to 10000. Not sure what's going on there.

I'm running Robolectric 3.8, and also tried with the 4.0 alpha version with no luck.

What am I missing?

Edit: For now I'm just running on the latest (what I can tell) supported api version, by annotating the test class(es) with @Config(sdk = [Build.VERSION_CODES.O_MR1]). This will give you Android 8.1.0 (api 27).


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/50870425/robolectric-does-not-support-api-level-28

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!