React Native Android应用启动失败及新建应用报错求助
我之前在开发React Native Android应用时也踩过这两个坑,给你整理几个亲测有效的解决办法,分场景来处理:
解决「Error type 3 Error: Activity class {com.test/com.test.MainActivity} does not exist」报错
这个问题大多是构建缓存、配置不一致或者旧应用残留导致的,试试这些步骤:
- 检查AndroidManifest.xml配置:打开
android/app/src/main/AndroidManifest.xml,确认MainActivity的配置正确,尤其是android:name和启动的intent-filter:<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> - 清理项目构建缓存:
- 进入Android目录执行清理:
cd android && ./gradlew clean - 回到根目录清除RN缓存:
cd .. && npx react-native start --reset-cache
- 进入Android目录执行清理:
- 卸载设备上的旧应用:不管是模拟器还是真机,彻底卸载包名为
com.test的应用,避免残留冲突 - 核对包名一致性:检查
android/app/build.gradle里的applicationId是否为com.test,要和Manifest中的包名完全一致
解决新创建应用的「The development server returned response error code:500」报错
新应用出现500错误通常是依赖、环境或服务器配置问题,试试这些方案:
- 确认Node.js版本兼容:React Native对Node版本有明确要求,建议使用LTS版本(比如18.x或20.x),你可以用
node -v查看当前版本,版本不兼容的话用nvm切换到合适版本 - 重新安装项目依赖:删除
node_modules文件夹、package-lock.json(或yarn.lock)文件,然后执行npm install(或yarn install)重新安装依赖 - 检查端口占用情况:RN开发服务器默认用8081端口,执行
lsof -i :8081(Mac/Linux)或netstat -ano | findstr :8081(Windows)查看是否有进程占用,杀掉占用进程后再重启服务器 - 手动启动开发服务器:先单独运行
npx react-native start,等终端显示「Loading dependency graph, done.」后,再开一个新终端执行react-native run-android - 检查Android SDK配置:确认本地已安装
android/build.gradle中指定的compileSdkVersion、targetSdkVersion对应的SDK包和构建工具,避免因SDK缺失导致构建失败
内容的提问来源于stack exchange,提问作者Mohammad Ghifari
相关产品推荐
相关产品推荐

