配置插件/解毒剂
当生成本地代码时, 配置自动配置解毒器的插件( E)npx expo prebuild) (中文(简体) ).
版本
确保您使用共同工作的版本 !
expo | detox | @config-plugins/detox |
|---|---|---|
| 53.0.0 (韩语) | 20.37.0 (简体中文) | ^10.0 |
| 52.0.0 (简体中文) | 20.28.0 (单位:千美元) | ^ 9.0.0 (中文(简体) ) |
| 51.0.0 (单位:千美元) | 20.20.3 联合国 | ^ 8.0.0 (韩语) |
| 50.0.0 (中文(简体) ) | 20.17.0 (简体中文) | ^7.0.0 (中文(简体) ) |
| 49.0.0 (单位:千美元) | 20.11.0 (单位:千美元) | ^ 6. 0 |
| 48.0.0 (简体中文) | 20.5.0 (中文(简体) ) | ^ 5.0.0 (中文(简体) ) |
| 47.0.0 (简体中文) | 19.13.0 (中文(简体) ) | ^ 4.0.0 (中文(简体) ) |
| 46.0.0 (单位:千美元) | 19.9.0 (中文(简体) ) | ^ 3. 0.0 (韩语) |
| 45.0.0 (单位:千美元) | 19.6.9 联合国 | ^ 2. 0 |
| 44.0.0 (单位:千美元) | 19.1.0 (中文(简体) ) | ^ 1.1.0 (中文(简体) ) |
| 43.0.0 (单位:千美元) | 19.1.0 (中文(简体) ) | ~ 1. 0 个 |
| 40.0.0 (单位:千美元) | 18.6.2 国家 | ~0.0 (中文(简体) ) |
最显著的是,所需最低程度的克特林版本改为: 1.3.50 在 SDK 40 到 1.4.21 在SDK 43. 中,在SDK 43. 不使用正确的版本可能导致 Android 构建错误,比如 Execution failed for task ':react-native-screens:compileDebugKotlin'. 或者说 Execution failed for task ':expo:compileDebugKotlin'.。 。 。 .
将软件包添加到您的 npm 依赖性
首先用纱线、 npm 或 npx expo install。 。 。 .
npx expo install detox @config-plugins/detox
Detox是iOS和Android的端到端(e2e)测试库. 您可以使用它实现本地工程的自动化使用 。 这个例子说明如何在本地建设的本土项目中使用Detox和Jest.
如何使用
- 安装方式
yarn或者说npm install- 安装 iOS 软件包 :
npx pod-install
- 安装 iOS 软件包 :
- 运行
yarn e2e:ios用于在模拟器上构建并测试 iOS 应用程序(只使用macOS).- 这个结合
yarn build:ios财务报告和审定财务报表yarn test:ios。 。 。 . - 你们可以跑
yarn test:ios --watch之后将测试保持在监视模式.
- 这个结合
- 运行
yarn e2e:android在谷歌模拟器上构建并测试Android应用程序(Genymotion需要额外配置).- 这个结合
yarn build:android财务报告和审定财务报表yarn test:android。 。 。 . - 你们可以跑
yarn test:android --watch之后将测试保持在监视模式.
- 这个结合
- 运行
yarn e2e:android-release在发布模式下构建和测试Android应用程序.
重新创建此示例
npx create-react-native-app -t blankcd输入项目
- 安装软件包 :
yarn add -D detox @config-plugins/detox @babel/core @babel/runtime @types/jest babel-jest jest jest-circus ts-jest- 触摸
tsconfig.json - 运行
expo start确保 TS 设置正确.
- 向您添加以下插件
app.json插件阵列( 预建前) 。 这将自动配置 Android 本地代码以支持 Detox :{ "plugins": ["@config-plugins/detox"] } - 生成本地代码
npx expo prebuild - 运行
yarn detox init -r jest
API 密码
该插件为额外的定制提供了道具. 每次更换道具或插件,都需要重建(并 prebuild(原始内容存档于2018-10-10). ). 本地应用. 如果没有添加额外的属性,则使用默认值.
skipProguard(单位:千美元)布尔: 禁用添加前卫分解app/build.gradle默认为false。 。 。 .subdomains(单位:千美元)字符串 [ *]:主机名可以添加到网络安全配置中. 过'*'允许所有域。 默认为['10.0.2.2', 'localhost']。 。 。 .
app.config.js
export default {
plugins: [
[
"@config-plugins/detox",
{
skipProguard: false,
subdomains: ["10.0.2.2", "localhost"],
},
],
],
};
财务问题
如果以下命令失败,可以通过运行子集命令获得更好的调试信息:
yarn e2e:ios数字 :yarn ios(构建iOS应用). xcodebuilding编译出的错误可能以更有用的格式显示(使用xcpretty).yarn e2e:android数字 :yarn android(构建Android应用). Android编译错误可能以更有用的格式显示.
yarn e2e:android 失败
如果得到错误:
detox[98696] ERROR: DetoxRuntimeError: Cannot boot Android Emulator with the name: 'Pixel_API_28'
HINT: Make sure you choose one of the available emulators: Pixel_3_API_30,Pixel_6_Pro_API_33,Pixel_C_API_30
请务必将第一个仿真器名称(我的情况是"Pixel API 28")与推荐的仿真器之一(我的情况是Pixel 3 API 30,Pixel 6 Pro API 33,Pixel C API 30)一起更改 detox.config.js 文件编号 devices.emulator.device.avdName. Android Studio可以创建更多的模拟器.
如果得到错误:
Error: app binary not found at '/Users/.../with-detox/android/app/build/outputs/apk/debug/app-debug.apk', did you build it
这意味着建设步骤失败, 确保运行 yarn android,以及 yarn build:android 在尝试前工作 yarn e2e:android 再来一次.
如果得到错误:
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
请务必禁用您计算机上运行的任何可能屏蔽请求的代理(即Charles Proxy). 您可能需要运行 yarn clean:android 在试图重建之前.
如果得到错误:
CLEARTEXT communication to [some host] not permitted by network security policy
这意味着你试图连接到一个 hTTP(不是 HTTPS) 没有 在你身边 subdomains 设置( 默认为 ['10.0.2.2', 'localhost']) (中文(简体) ). 设置您的子域设置 。 例如,如果将Detox建设成dev客户端,您会希望确保您可以连接到您的地铁服务器:
module.exports = {
plugins: [
[
"@config-plugins/detox",
{
subdomains:
process.env.EAS_BUILD_PROFILE === "development"
? "*"
: ["10.0.2.2", "localhost"],
},
],
],
};