Robolectric 不支持 API 级别 28 [英] Robolectric does not support API level 28

查看:95
本文介绍了Robolectric 不支持 API 级别 28的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然这个问题已经在其他线程的先前版本中得到了回答,但现在似乎没有一个答案对我使用 api 28 有效,所以..

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..

所有 Robolectric 测试在 api 27 上运行良好.现在,当我的应用程序 api 目标为 28 时,它们都失败了.

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

我有

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

在我的测试课上.

深入了解 Robolectrics 内部的 SdkConfig.java,看起来他们添加了对 api 28 的支持:

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

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

但是在调试器中评估该行代码时,Build.VERSION_CODES.P 的计算结果为 10000.不确定那里发生了什么.

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

我正在运行 Robolectric 3.8,并且还尝试了 4.0 alpha 版本,但没有成功.

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

我错过了什么?

现在我只是在最新的(我能说的)支持的 api 版本上运行,通过使用 @Config(sdk = [Build.VERSION_CODES.O_MR1]).这将为您提供 Android 8.1.0 (api 27).

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).

推荐答案

第二次 这已经从快照毕业,现在可以使用

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

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

即您不再需要 Maven 快照行.

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

此问题现已修复并可在快照构建中使用.在您的 gradle 构建文件(应用程序级别)中添加

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" }
}

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

<小时>

现在这个问题已经更新了来自贡献者的信息似乎将有一个新的 4.0 alpha 版本在本周内修复这个问题.


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.

这篇关于Robolectric 不支持 API 级别 28的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆