国产手机Android R(Android 11)系统执行Espresso UI(AndroidX)遇到的问题总结

最近在 Android R(Android 11)系统上执行以前写的Espresso UI(AndroidX)单元测试用例的时候,发现在 联想拯救者电竞手机Pro(128GB) 系统版本 12.5.225上,如果测试用例申请了通讯录写入权限,如下:

<uses-permission android:name="android.permission.WRITE_CONTACTS" />

那么测试用例执行的时候,会报告如下错误:

Test running failed:Process crashed.

详细的logcat日志如下:

D/Zygote: Forked child process 10664
I/ActivityManager: Start proc 10664:xx.test/u0a274 for added application xx.test
I/AutoRun: AutoRunServices: ProcessStateHandler: sendKillAppRequest: [uid = 10274, pid = 10664, package name = xx.test mOtherPids = null, mStartupTime = 0, mDelay = 0, mCount = 0]
I/adbd: jdwp connection from 10664
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
I/yboard.biz.tes: The ClassLoaderContext is a special shared library.
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
I/Perf: Connecting to perf service.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/MonitoringInstr: Instrumentation started!
I/AndroidJUnitRunner: Waiting for debugger to connect...
I/System.out: Sending WAIT chunk
I/ActivityManager: Killing 10664:xx.test/u0a274 (adj 0): permissions revoked
I/Zygote: Process 10664 exited due to signal 9 (Killed)
I/libprocessgroup: Successfully killed process cgroup uid 10274 pid 10664 in 44ms

目前测试发现,即使通过GrantPermissionRule授予权限,也是没用的,代码根本来不及执行,应用就一下被系统杀死了。

目前只能是不测试这部分功能。

@Rule
public final GrantPermissionRule rule = GrantPermissionRule.grant(android.Manifest.permission.WRITE_CONTACTS);

OPPO/VIVO/小米等手机上,需要手工开启 后台弹出界面权限 才能执行单元测试。有个思路是通过UI Automator来自动开启这个权限,暂时还需要测试一下。

参考链接


发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注