13

I'm aware there's a plethora of questions/answers regarding this issue. However, I have spent the past few days trying a number of solutions I've found on SO and none have worked thus far.

My error:

BUILD SUCCESSFUL in 52s
372 actionable tasks: 352 executed, 20 up-to-date
info Running C:\Users\User\AppData\Local\Android\Sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081
info Starting the app on emulator-5554 (C:\Users\User\AppData\Local\Android\Sdk/platform-tools/adb -s emulator-5554 shell am start -n mypackage/mypackage.MainActivity)...
Starting: Intent { cmp=mypackage/.MainActivity }
Error type 3
Error: Activity class {mypackage/mypackage.MainActivity} does not exist.

Here is a list of all the things I've attempted to do based on other SO posts:

Attempts

  1. Running adb kill-server, adb start-server, then react-native run-android

  2. Running adb reverse tcp:8081 tcp:8081, then react-native run-android (a senior dev I used to work with told me the issue might be related to this a long time ago, but I cannot get in touch with him)

  3. Uninstalling the App from the Emulator, as well as my physical device

  4. Build -> Clean Project

  5. Files -> Invalidate Cache / Restart

  6. Files -> Sync Project with Gradle Files

  7. Build -> Rebuild Project

  8. Deleted gradle cache files in /project/android/.gradle/5.1.1

  9. AndroidManifest.xml -> <activity android:name=".MainActivity" to <activity android:name="packagename.MainActivity"

  10. android/app/build.gradle to view buildTypes

debug {
  applicationIdSuffix ".debug"
}
stagingRelease {
  applicationIdSuffix ".staging"
}
release {

}

Ran react-native run-android --variant=[debug] --appIdSuffix '[.debug]'

&&

Ran react-native run-android --variant=[stagingRelease] --appIdSuffix '[.staging]'

(these came with different errors)

  1. Make sure android/app/build.gradle
defaultConfig {
        applicationId "WHATEVER_THIS_IS" 
}

needs to match android/app/src/main/java/com/app_name/MainActivity.java line one:

package WHATEVER_THIS_IS;

needs to match android/app/src/main/java/com/app_name/MainApplication.java line one:

package WHATEVER_THIS_IS;

needs to match android/app/src/main/AndroidManifest.xml line one:

package="WHATEVER_THIS_IS">
  1. Went to android/app/build.gradle and changed:
splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}

to

splits {
    abi {
        reset()
        enable true
        universalApk true  // If true, also generate a universal APK
        include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
    }
}
  1. Went to C:/Users/User/.gradle to delete the cache. Was unable to delete everything, as I kept getting alerts that many of the files/folders inside are currently "open in another program" (untrue as far as I can tell)

Nothing worked.

Posts I followed for solutions

Error type 3 Error: Activity class {} does not exist

https://github.com/facebook/react-native/issues/8653

"react-native run-android" - BUILD is SUCCESSFUL but get error type 3 Error: Activity class MainActivity does not exist

Error type 3. Activity class {com.awesome_project/ com.awesome_project.MainActivity} does not exist in react native (Android device)

Cin88
  • 425
  • 2
  • 6
  • 20

7 Answers7

13

Even I was facing the same issue, and finally I found a solution.

  1. Delete app/build directory.
  2. cd into android and run ./gradlew uninstallAll (ie, your device should be connected to your system). It started working after following the above steps.
ferdynator
  • 6,245
  • 3
  • 27
  • 56
LukeRebel
  • 139
  • 2
  • 4
  • 1
    for the 2 step: Windows environment to run .\gradlew uninstallAll. – user909016 Feb 15 '22 at 06:17
  • I got the OPs error after uninstalling the App on my phone (through the phone). Trying to start the app multiple times didn't work, and gave no errors at first. The error appeared after a reboot of my dev computer. The steps in this answer solved it. – Wu Wei Jan 28 '23 at 00:39
  • Didn't worked for me – Maruf Sharifi Jun 24 '23 at 10:04
5

For those who might experienced the same situation like the one I faced!

Explanation:

Note: I'm working on my app in eject mode

I have updated my react-native npm package to the latest version (By the time of writing this answer @0.67.2). And then when I was staring (running) my android app in the emulator using (npx react-native run-android), I have experienced this error:

Error type 3 - Error: Activity class {*.MainActivity} does not exist.

Solution which worked me:

  1. In Android studio => Virtual device manager => I wiped user data (Please note the attached screenshot) enter image description here

  2. In Visual studio, in the root of your project, locate android folder. delete build folder inside app folder. (please note the attached screenshot) enter image description here

  3. run npx react-native run-android and you must be able to get your app running smoothly again.

Hooman
  • 1,775
  • 1
  • 16
  • 15
4

For RN projects try to run adb reverse tcp:8081 tcp:8081

1

Follow these steps

  1. Check if device is connected. Use command adb devices. If it shows your device than move to next step.
  2. Run the command adb uninstall com."app_name". If you get a success than move to next step.
  3. Run the command npx react-native run-android inside the project root folder.
1

I Got The Error

BUILD SUCCESSFUL in 3m 10s 215 actionable tasks: 215 executed
info Connecting to the development server...
info Starting the app on "EMAY8PU4VGAEN779"...
Starting: Intent { cmp=com.modernlaundaryforapk/.MainActivity }
Error type 3
Error: Activity class
{com.modernlaundaryforapk/com.modernlaundaryforapk.MainActivity} does
not exist.

and here is the solution which worked for me

Open the android/app/build.gradle file in your project.

Locate the defaultConfig section within the file. Inside this section, you will find the applicationId

defaultConfig {
    applicationId "com.myproject"
}

Now, open android/app/src/main/java/com/app_name/MainActivity.java and check the first line

package com.myproject;

Make sure that com.myproject matches the applicationId value.

Similarly, verify that the package name in AndroidManifest.xml matches the applicationId value. Open the file located at android/app/src/main/AndroidManifest.xml and check the first line:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myproject">

Ensure that the package name com.myproject matches the applicationId value.

After verifying that all the package names are consistent, you can now attempt to run your React Native app using the following command:

npx react-native run-android

If the issue persists, you can try uninstalling the app from your device or emulator. Run the following command:

adb uninstall com.myproject

replace com.myproject with your actual applicationId value:

Then, rerun the command:

npx react-native run-android

This should resolve the issue, and your app should run correctly.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 12 '23 at 18:54
0
npx react-native run-android --variant devdebug --appIdSuffix dev

make sure your variant/appIdSuffix name is correct and match the above line

aman yadav
  • 11
  • 2
0

For me it turned out I had the app installed in "Work" mode, I thought deleting it from "Personal" mode would fully delete it but apparently it didn't

Alexander Vitanov
  • 4,074
  • 2
  • 19
  • 22