481
votes

I have an IntelliJ Android project, that I successfully imported to Android Studio 0.4.0. It works perfectly if I don't change anything in manifest. However, when I want to change the launcher activity and run, it fails with this error:

Launching application: com.trackingeng/LandingActivity.
DEVICE SHELL COMMAND: am start -D -n "com.trackingeng/LandingActivity"  
    -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN  
    cat=[android.intent.category.LAUNCHER] cmp=com.trackingeng/LandingActivity }
Error type 3
Error: Activity class {com.trackingeng/LandingActivity} does not exist.

When I click Sync Project with Gradle files, it outputs:

Project Sync
The project 'TrackingEng' is not a Gradle-based project

Run settings: enter image description here

30
Where is your original AndroidManifest.xml file?twlkyao
In the same place, under main folder in project.Jacob
I mean is this picture in the post is your original AndroidManifest.xml or not.twlkyao
I have found a thread, hope could help. stackoverflow.com/questions/19670607/…twlkyao
Though not effective in the OP's case, doing a gradle sync solved Error: Activity class {...} does not exist. for me.dinosaur

30 Answers

733
votes

I faced a similar problem after refactoring.
This is what i did to resolve this issue:

  1. Cleaned the Project
  2. Deleted the Build directory
  3. Restarted Android Studio
  4. Rebuild the Project
  5. Run
  6. Optionally (Go to the files menu on android, click on "Invalidate Caches / Restart..." uninstall the app on your phone and try again)

And everything worked fine!
I think the key is to restart your IDE.

Hope this helps you or anyone else!

Edit 1:
If the above steps don't work for you, then deleting Gradle cache seems to be a solution, as pointed out by @Yasitha.

Edit 2
As suggested by a couple of users in the comments below, sometimes the issue can be resolved by completely removing and reinstalling the app from your device.
Simply type adb uninstall <package> in terminal to completely remove app from the device.

Edit 3
As mentioned in Abhishek's Answer, one should also try deleting the app from your device in case multiple users are set up on your device.
Simply go to Mobile Settings > Apps > [Your App] > More > Uninstall App for All Users

UPDATE for Android Studio 2.1 and up

When running Android Studio 2.1 and up you can also encounter this issue when you have the instant run option enabled in your preferences (is enabled by default).

To disable this option go to the Preferences option in the Android Studio top menu and look for Instant Run so you can uncheck the first checkbox on that screen.

Disable Instant Run in Android Studio 2.1+

Anyway that fixed it for me. Originally pointed out by user @yusufonder. I discovered this was the issue since gradle install still worked.

354
votes

May be helpful for someone:--

Sometimes when testing on a device, the app doesn't uninstall properly. To verify and fix this:

  1. Go to Settings.
  2. Go to Apps.
  3. Select your app. (here, you can verify that your app is not uninstalled properly).
  4. Open the overflow menu on the top right and select Uninstall for all users.
  5. Done. Try to install then launch your app again.
102
votes

I would face this problem when uninstalling the app via the device (i.e. dragging the app to the "Uninstall" option). But here is the proper way to uninstall:

Use the ./gradlew uninstallAll command. This will prevent the Error: Activity class {HomeActivity} does not exist. error.

Update:

If you’re lazy you can use the abbreviation for this task: ./gradlew uA.

Or define aliases for common gradle tasks in your .bash_profile, doing so will save time, typing, and you won’t have to remember every command nor worry about typos. I suggest doing this.

74
votes

I had the same issue, and this is how I fixed it.

Go to Gradle > Tasks > Install > UninstallAll

enter image description here

73
votes

This happens when you do the following

  • connect your device/emulator
  • run the app from Android Studio (AS)
  • use/test the app and uninstall it from the device while it is still connected to your computer
  • try to run the app again from AS

AS thinks you still have the app in your device.

tl;dr - To resolve this, you can simply disconnect your device after uninstalling the app and reconnect it.

51
votes

The App is already installed for Another user. Please try to uninstall the same app for all the user. Then try.

Or you can try after running adb command.

adb uninstall PACKAGE_NAME

where PACKAGE_NAME is the full name such as com.example.myapp

30
votes

I had the same error after renaming/refactoring. What I did was add the applicationId property attribute to my build.gradle file, and set its value to the application package.

In build.gradle:

android {
defaultConfig {
    applicationId "com.example.myapp"  
  }
}
20
votes

Try changing the name of the Activity in your AndroidManifest.xml file.

Right now it says:

<activity android:name="LandingActivity" >

Try either adding a period to the beginning of the Activity's name:

<activity android:name=".LandingActivity" >

Or adding the package name to the beginning of the Activity's name:

<activity android:name="com.trackingeng.LandingActivity" >

It also may be a problem that your package name has only two components separated by periods (your package name is "com.trackingeng"; a more standard package name would be "com.trackingeng.app")

20
votes

In my case i uninstalled application from phone it after that the problem began but, the below command worked for me.

Execute below command in terminal/cmd

adb uninstall <package_name>

package_name something like com.example.applicationname Then, try to reinstall the application. It should work.

18
votes

Follow Steps Below Go to Mobile setting > Apps > Your App > More > Hit Uninstall app for all users.

Reason : Because you are having multiple users in your phone and you had uninstalled that app for only one.

ENJOY:

15
votes

I think another reason that issue happen is that it is not fully deleted for all users on the device.

Go to Settings -> Apps - > Your Apps -> Click to the 3 dots on the top right -> Uninstall for all users

It works for me. It happen especially you change the icons of the app or messing around with the AndroidManifest.xml file.

13
votes

For me, the problem was that AndroidStudio thought that the app was still on the device.

To fix it:

  1. restart the adb daemon; in a terminal or command prompt, enter:

    adb kill-server
    adb start-server
    
  2. try to launch your app.

  3. if it still doesn't work, check out this answer.

make sure the platform-tools of the Android SDK is added to your system path variables!

13
votes

This happened to me using react-native run-android because my package name did not match my app ID. Just add --appId YOUR_APP_ID.

10
votes

Below command worked for me. Sometime partial uninstallation of the app also causes this.

Execute below command in terminal/cmd

adb uninstall <package_name>

Then, try to reinstall the application. It should work.

9
votes

for me, on android 6 when i uninstalled the app it actually went to disabled instead of being removed from device.

Settings > Apps > click on your app and uninstall

this fixed it for me

8
votes

When I got this problem I always try this solution and it works.

Instant Run disable 

Build -> Clean Project

File -> Invalidate Caches / Restart

But I found an exception this once. This solution doesn't work for me. Then I find out the problem is Emulator cash. I just do Wipe data and Cold boot now and the problem is solved.

enter image description here

7
votes

Be warned that if you have multiple Profiles set on the device, your app might already exist in one of the other Profiles.

Uninstalling the app from all the Profiles resolved the issue for me.

6
votes

For me it was a very specific problem, I've got a Lg g5 to test my application on, and to reset my apps data I uninstalled it on the phone, but the phone has a "nice" feature to don't uninstall apps immediatly so you might can reinstall them within one day. So the app was installed but not usable(disabled) after removing the app from the phone completely it worked.

6
votes

In my case, it was because the app I was trying to launch was installed for a different user on the device. Go to Settings -> Apps (All apps) and and select the app. Click on the overflow menu and select "Uninstall for all users". This should solve the problem.

6
votes

Just in case anyone runs into my issue and has no luck with the other solutions... I was trying to start an activity through adb for FireTV while debugging Amazon launcher integration. However, my project had 60 different build variants (multi-platform, multi-app project) and the ApplicationId didn't match any classpath since the runtime package (and classpaths) were different from the applicationId.

I was trying to run adb shell am start -n com.myappid.example.packageone.packagetwo/com.myappid.example.packageone.packagetwo.MySplashActivity

(Of course I had tried many combinations with com.runtimepath.example since I had the added challenge of a different applicationId in my build.gradle and another at runtime)

What finally helped was this post https://stackoverflow.com/a/36255727/5970652

Which revealed a different format! com.myappid.example/com.runtimepath.example.packageone.packagetwo.MySplashActivity

So if you have a different runtime classpath try specifying with the build.gradle applicationId before the slash and the runtime classpath afterwards.

You can also get these values from BuildConfig.APPLICATION_ID and this.getLocalClassName() respectively if you want to log them in logcat.

6
votes

In my case there was next reason:

I have 2 users: me and Guest. and app was installed on both of them but deleted only at first.

when I switched to Guest screen and delete app from there, app installed ok.

hope this will help someone :)

6
votes

I use Android Studio 3.2 Beta 5, faced with the same issue

Go to

File -> Invalidate Caches / Restart...

Solved problem for me

6
votes

If you have uninstalled the application manually from the device and you have multi user set up, this error could happen. The application needs to be uninstalled from all the users in the device.

6
votes

Some times application install on Guest user on your mobile, So try to switch Guest and uninstall the application.

In addition, try to execute the following command to uninstall application adb uninstall package "Your package Name"

5
votes

Even I had the same problem but none of the above solutions worked for me. The problem was that, I had froze the particular app which I was trying to run via Titanium Backup due to which I got the above error. I tried both in Eclipse and Android Studio.

After the realization I just unistalled the app and then ran it again.

Problem Solved :-)

5
votes

I'd like to share the trick that helped in my case. I uninstalled the application from the device and nothing of clean/rebuild/Android Studio restart operations didn't help.

Since Android Studio thinks that the application is still installed on the device and doesn't deploy it, you can force the installation using the ADB:

adb install -r <your_application_from.apk>

where -r means reinstall the app, keeping its data.

5
votes

I have a Samsung Galaxy. Searching in the settings above didn't work because it didn't show up at all in my Apps settings.

I found the application on my phone by typing the name of the app in the search field. I realized it was in the "Work"(using Mobile@Work) profile and removed it. You can find the settings for the profile by going to Settings->Work profile->Apps

I hope this helps somebody who may not find it the same way that many of the other answers stated it could be found in the settings.

5
votes

Faced this problem in android studio 3.5.1 Took me a day to solve this problem,Tried everything including cleaning cache,restart and renaming package name as well. So if any of above did't work than try this.

Just go to gradle > Tasks > Install > UninstallAll

Here is the link: Error type 3: Activity Class {...} does not exist

4
votes

I also faced the same problem somewhere in the past. Such problems actually occurs when we do some refactoring like - renaming, moving files within the project etc. Renaming and Moving files require changes in the gradle file so whenever you rename or move some file just clean the project:

Build -> Clean Project

Cleaning the project just removes the .class files and recompiles the project. Basically, it forces a project rebuild.

Sometimes such types of errors did not cleaned on cleaning project then try to uninstall the app from the device (either it is emulator or physical one) and run the app again. Hope this will help you, it helps me 50% times.

Note:- Whenever you got any error just don't go to google, Clean the project if this not work do what you want to google.

4
votes

I had the same issue and I solved it refactoring my activity launcher, just change the class name and it works.