React Native Expo应用无法启动开发模式的问题求助
原本项目使用@react-native-firebase/app和@react-native-firebase/auth可以正常运行,换设备拉取Git代码后,执行npx eas build选择Android构建成功,但运行npx expo start启动开发构建时出现以下错误:
CommandError: No development build (com.deme.myapp) for this project is installed. Please make and install a development build on the device first.
已按要求将Firebase的.plist和.json配置文件放到正确位置,昨天还能正常运行,换设备后就出现问题。
配置文件
app.json:
{ "expo": { "name": "my-app", "slug": "my-app", "version": "1.0.0", "orientation": "portrait", "icon": "./assets/icon.png", "userInterfaceStyle": "light", "splash": { "image": "./assets/logo.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "assetBundlePatterns": ["**/*"], "ios": { "supportsTablet": true, "bundleIdentifier": "com.deme.myapp", "googleServicesFile": "./GoogleService-Info.plist" }, "android": { "adaptiveIcon": { "foregroundImage": "./assets/logo.png", "backgroundColor": "#ffffff", "googleServicesFile": "./google-services.json" }, "package": "com.deme.myapp" }, "web": { "favicon": "./assets/favicon.png" }, "scheme": "my-app", "plugins": [ "expo-router", "@react-native-firebase/app", "@react-native-firebase/auth" ], "extra": { "router": { "origin": false }, "eas": { "projectId": "{{HIDDEN FOR THREAD}}" } } } }
eas.json:
{ "build": { "development": { "developmentClient": true, "distribution": "internal" }, "preview": { "distribution": "internal" }, "production": {} } }
package.json:
{ "name": "my-app", "version": "1.0.0", "main": "expo-router/entry", "scripts": { "start": "expo start", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web" }, "dependencies": { "@firebase/analytics": "^0.10.0", "@firebase/app": "^0.9.23", "@firebase/auth": "^1.4.0", "@firebase/firestore": "^4.3.2", "@react-native-firebase/app": "^18.6.1", "@react-native-firebase/auth": "^18.6.1", "axios": "^1.6.2", "expo": "~49.0.15", "expo-constants": "~14.4.2", "expo-firebase": "^0.0.0-alpha.0", "expo-image": "~1.3.5", "expo-linear-gradient": "~12.3.0", "expo-linking": "~5.0.2", "expo-router": "^2.0.0", "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "expo-system-ui": "~2.4.0", "firebase": "^10.6.0", "react": "18.2.0", "react-native": "0.72.6", "react-native-gesture-handler": "~2.12.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0" }, "devDependencies": { "@babel/core": "^7.20.0" }, "private": true }
解决步骤
确保安装的是development构建包
执行npx eas build时如果没指定profile,默认会用preview或production版本,这些不属于开发客户端。要明确构建开发版本:npx eas build --profile development --platform android构建完成后把生成的APK安装到测试设备上,再运行
npx expo start即可正常连接。改用本地编译命令
不想用EAS远程构建的话,直接用本地编译并安装到设备:npx expo run:android这个命令会自动编译项目并安装到连接的Android设备,之后启动
npx expo start就不会报错。修复app.json配置错误
你把Android的googleServicesFile放在了adaptiveIcon节点下,这是错误的,应该移到Android根节点:"android": { "adaptiveIcon": { "foregroundImage": "./assets/logo.png", "backgroundColor": "#ffffff" }, "package": "com.deme.myapp", "googleServicesFile": "./google-services.json" }清理依赖冲突
package.json里同时安装了@react-native-firebase/*和firebase、@firebase/*、expo-firebase,这些会导致版本冲突。保留@react-native-firebase/app和@react-native-firebase/auth,删除其他重复的Firebase相关依赖后重新安装:npm uninstall @firebase/analytics @firebase/app @firebase/auth @firebase/firestore firebase expo-firebase npm install清理缓存
清除Expo和项目缓存:npx expo start --clear rm -rf node_modules package-lock.json npm install cd android && ./gradlew clean && cd ..
内容的提问来源于stack exchange,提问作者Demetris

