You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native安卓项目VS模拟器启动失败:Error type3 Activity类不存在求助

Fixing "Activity class {com.project/com.project.MainActivity} does not exist" in React Native

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:

    1. 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".
    2. Or use adb to force a full uninstall: run adb uninstall com.project (replace com.project with your actual package name) in your terminal. This ensures no old installation files hang around.
  • Double-check MainActivity and Manifest setup
    Open your MainActivity.java and confirm it extends ReactActivity (the default for React Native projects). Then head to AndroidManifest.xml to verify:

    • The <activity> tag's android:name is either .MainActivity or the full path com.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>
      
  • Verify applicationId in gradle config
    Open android/app/build.gradle and check the defaultConfig section. Make sure the applicationId matches 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)

    1. Fully shut down your Visual Studio emulator, then launch it again.
    2. Stop your Metro server (press Ctrl+C in the terminal where it's running), then restart it with cache reset: npx react-native start --reset-cache
    3. Finally, run npx react-native run-android again.
  • Fix adb connection issues
    Sometimes the Android Debug Bridge gets stuck. Run these commands in order:

    adb kill-server
    adb start-server
    adb devices
    

    Make 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 the android/app/build directory completely. Then run cd android && ./gradlew assembleDebug to rebuild the app from scratch, followed by npx react-native run-android.

内容的提问来源于stack exchange,提问作者Thara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:56:56