React Native安卓项目VS模拟器启动失败:Error type3 Activity类不存在求助
Hey there, let's work through this annoying issue together! I've dealt with this exact problem when setting up React Native projects with Android emulators, so here are some actionable fixes beyond the steps you've already tried:
彻底清理模拟器上的旧应用残留
Sometimes the emulator leaves behind broken app data even after uninstalling. Try this:- Open your Visual Studio Android emulator, find any leftover icon for your app, long-press it, select uninstall, and make sure to check "Delete app data".
- Or use adb to force a full uninstall: run
adb uninstall com.project(replacecom.projectwith your actual package name) in your terminal. This ensures no old installation files hang around.
Double-check MainActivity and Manifest setup
Open yourMainActivity.javaand confirm it extendsReactActivity(the default for React Native projects). Then head toAndroidManifest.xmlto verify:- The
<activity>tag'sandroid:nameis either.MainActivityor the full pathcom.project.MainActivity - The activity has the correct intent filter set as the launcher:
<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>
- The
Verify applicationId in gradle config
Openandroid/app/build.gradleand check thedefaultConfigsection. Make sure theapplicationIdmatches your package name exactly:defaultConfig { applicationId "com.project" minSdkVersion ... targetSdkVersion ... // other configs }A typo here is a super common culprit that's easy to miss!
Restart everything (yes, really)
- Fully shut down your Visual Studio emulator, then launch it again.
- Stop your Metro server (press
Ctrl+Cin the terminal where it's running), then restart it with cache reset:npx react-native start --reset-cache - Finally, run
npx react-native run-androidagain.
Fix adb connection issues
Sometimes the Android Debug Bridge gets stuck. Run these commands in order:adb kill-server adb start-server adb devicesMake sure your emulator shows up in the devices list before trying to run the app again.
Delete and rebuild the build folder
If all else fails, delete theandroid/app/builddirectory completely. Then runcd android && ./gradlew assembleDebugto rebuild the app from scratch, followed bynpx react-native run-android.
内容的提问来源于stack exchange,提问作者Thara

