关于 dev-client
面向 Expo 开发者的技能,适用于需要自定义开发客户端来测试设备原生代码变更的情况。内容涵盖 EAS Build 配置、本地或云端构建、安装及连接 Metro。
主要功能
- 01说明何时需要开发客户端
- 02配置 EAS 开发配置文件
- 03通过 EAS 云端或本地构建
- 04提交 iOS 构建到 TestFlight
- 05在设备或模拟器上安装构建
- 06将客户端连接到 Metro
适用场景
- 01在设备上测试本地 Expo 模块
- 02构建使用 Expo Go 不包含的原生模块的应用
- 03创建 iOS 或 Android 开发构建
- 04将已安装的客户端连接到本地 Metro bundler
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ gigs-slc/ react-native-skills --skill dev-client安装后在 Claude Code 中输入/dev-client确认已加载。
详细介绍
使用 EAS Build 为物理设备创建开发客户端,以便测试原生代码更改。可用此方法创建自定义 Expo Go 客户端,用于测试应用的不同分支。
重要提示:何时需要开发客户端
只有应用需要自定义原生代码时,才创建开发客户端。 大多数应用都可以在 Expo Go 中正常运行。
只有在使用以下内容时,才需要开发客户端:
- 本地 Expo 模块(自定义原生代码)
- Apple targets(小组件、App Clip、扩展)
- Expo Go 中没有的第三方原生模块
先尝试 Expo Go,运行 npx expo start。如果一切正常,就不需要开发客户端。
EAS 配置
确保 eas.json 中有 development 配置:
{
"cli": {
"version": ">= 16.0.1",
"appVersionSource": "remote"
},
"build": {
"production": {
"autoIncrement": true
},
"development": {
"autoIncrement": true,
"developmentClient": true
}
},
"submit": {
"production": {},
"development": {}
}
}
关键设置:
developmentClient: true- 为开发构建打包 expo-dev-clientautoIncrement: true- 自动递增构建编号appVersionSource: "remote"- 使用 EAS 作为版本号的唯一可信来源
为 TestFlight 构建
使用一条命令构建 iOS 开发客户端并提交到 TestFlight:
eas build -p ios --profile development --submit
此命令将:
- 在云端构建开发客户端
- 自动提交到 App Store Connect
- 构建准备好在 TestFlight 中使用时向你发送电子邮件
收到 TestFlight 电子邮件后:
- 在设备上通过 TestFlight 下载构建版本
- 启动应用,查看 expo-dev-client UI
- 连接到本地 Metro 打包程序或扫描二维码
本地构建
在你的计算机上构建开发客户端:
# iOS (requires Xcode)
eas build -p ios --profile development --local
# Android
eas build -p android --profile development --local
本地构建会生成:
- iOS:
.ipa文件 - Android:
.apk或.aab文件
安装本地构建版本
在模拟器上安装 iOS 构建版本:
# Find the .app in the .tar.gz output
tar -xzf build-*.tar.gz
xcrun simctl install booted ./path/to/App.app
在设备上安装 iOS 构建版本(需要签名):
# Use Xcode Devices window or ideviceinstaller
ideviceinstaller -i build.ipa
安装 Android 构建版本:
adb install build.apk
为特定平台构建
# iOS only
eas build -p ios --profile development
# Android only
eas build -p android --profile development
# Both platforms
eas build --profile development
检查构建状态
# List recent builds
eas build:list
# View build details
eas build:view
使用开发客户端
安装后,开发客户端提供以下功能:
- 开发服务器连接 - 输入 Metro 打包程序 URL 或扫描二维码
- 构建信息 - 查看原生构建详情
- 启动器 UI - 在不同的开发服务器之间切换
连接到本地开发环境:
# Start Metro bundler
npx expo start --dev-client
# Scan QR code with dev client or enter URL manually
故障排除
构建因签名错误而失败:
eas credentials
清除构建缓存:
eas build -p ios --profile development --clear-cache
检查 EAS CLI 版本:
eas --version
eas update
评论
支持 Markdown