You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Espresso截图测试调用writeToTestStorage报无Content Provider错误如何解决

Espresso 截图测试 writeToTestStorage 报错解决方案
  • 报错根因:No content provider registered 错误是因为缺少 AndroidX Test Services 依赖,writeToTestStorage 依赖测试服务内置的 ContentProvider 实现文件读写,无需开发者自行配置 Provider。
  • 具体修复步骤:
    1. 在模块级 build.gradle 中添加统一版本的 AndroidX Test 相关依赖:
    dependencies {
        // AndroidX 测试核心依赖
        androidTestImplementation "androidx.test:core:1.5.0"
        androidTestImplementation "androidx.test:runner:1.5.2"
        // 必须添加测试服务依赖,提供存储相关实现
        androidTestImplementation "androidx.test.services:test-services:2.1.0"
    }
    
    1. 确认 build.gradle 的 defaultConfig 区块配置了正确的测试运行器:
    android {
        defaultConfig {
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    }
    
    1. 删除 Manifest 中自行添加的 WRITE_EXTERNAL_STORAGE 权限:该 API 通过测试服务读写应用内部专属测试目录,不需要申请外部存储权限,多余的权限配置反而可能触发不同安卓版本的权限适配问题。
  • API 文档获取说明:writeToTestStorage 的完整用法可以直接在 Android Studio 中通过跳转到方法定义查看官方注释,注释包含参数说明、存储路径、注意事项等完整信息。测试完成后生成的截图可以在设备的 /sdcard/Android/data/[你的应用包名]/files/test_output/ 目录下获取。

内容的提问来源于stack exchange,提问作者Denis Podzorov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 05:24:05