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

执行detox build时react-native-encrypted-storage编译AndroidTest失败求助

解决Detox构建时./gradlew assembleAndroidTest失败的问题

问题背景

执行detox build时,在./gradlew assembleAndroidTest步骤报错:

Task :react-native-encrypted-storage:processDebugAndroidTestManifest FAILED
app/node_modules/react-native-encrypted-storage/android/build/intermediates/tmp/manifest/androidTest/debug/tempFile1ProcessTestManifest1073565797895292553.xml:27:9-33:20 Error:
android:exported needs to be explicitly specified for element <activity#androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity>.

原因是项目targetSdkVersion=33(Android 12+),系统要求所有带有intent filter的组件必须显式声明android:exported属性,而react-native-encrypted-storage依赖的测试组件未满足该要求。

解决方案

1. 优先升级react-native-encrypted-storage到最新版本

多数主流库已针对Android 12+修复了android:exported的问题,执行命令更新:

npm install react-native-encrypted-storage@latest
# 或使用yarn
yarn add react-native-encrypted-storage@latest

更新后重新执行detox build验证。

2. 手动通过清单合并规则强制添加属性

如果升级库无效,在你的app模块的android/app/src/androidTest/AndroidManifest.xml中添加以下配置,强制为问题组件声明android:exported:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="你的应用包名">

    <application>
        <!-- 修复测试组件的android:exported缺失问题 -->
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
            android:exported="false"
            tools:node="merge"
            tools:replace="android:exported" />
    </application>
</manifest>

替换你的应用包名为项目实际包名,执行./gradlew clean assembleAndroidTest重新构建。

3. 升级AndroidX Test依赖版本

旧版AndroidX Test库可能存在该问题,在项目根目录的build.gradle中更新AndroidX Test版本:

buildscript {
    ext {
        // 保留原有配置,添加或更新以下行
        androidXTestCoreVersion = "1.5.0"
        androidXTestRunnerVersion = "1.5.2"
    }
}

确保app模块的build.gradle中依赖的AndroidX Test库使用上述版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 07:56:08