Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 935
Jacob Avatar asked Jan 04 '14 00:01

Jacob


23 Answers

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.

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

Edit 4
As mentioned by Yassin Ajdi, executing the uninstallAll Gradle task can also fix the issue.
You can go to Gradle > Tasks > Install > uninstallAll to get the job done.

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.

like image 75
S1LENT WARRIOR Avatar answered Oct 02 '22 15:10

S1LENT WARRIOR


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.
like image 36
Nicks Avatar answered Oct 02 '22 14:10

Nicks


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.

like image 43
Sakiboy Avatar answered Oct 02 '22 15:10

Sakiboy


I had the same issue and this is how I fixed it:

Go to Gradle > Tasks > Install > uninstallAll

enter image description here

like image 23
Yassin Ajdi Avatar answered Oct 02 '22 16:10

Yassin Ajdi


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.

like image 36
Ankit Avatar answered Oct 02 '22 14:10

Ankit


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

like image 40
Dipendra Sharma Avatar answered Oct 02 '22 16:10

Dipendra Sharma


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"  
  }
}
like image 30
Blue5hift Avatar answered Oct 02 '22 14:10

Blue5hift


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.

like image 40
Bercove Avatar answered Oct 02 '22 15:10

Bercove


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")

like image 20
Josh Avatar answered Oct 02 '22 14:10

Josh


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.

like image 37
phatmann Avatar answered Oct 02 '22 15:10

phatmann


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.

like image 33
Abhishek Avatar answered Oct 02 '22 15:10

Abhishek


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.

like image 20
Long Dao Avatar answered Oct 02 '22 14:10

Long Dao


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!

like image 29
Eric Avatar answered Oct 02 '22 16:10

Eric


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.

like image 41
Ronak Mehta Avatar answered Oct 02 '22 16:10

Ronak Mehta


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

like image 28
Md Imran Choudhury Avatar answered Oct 02 '22 15:10

Md Imran Choudhury


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

like image 9
Zain Ullah Muhammad Avatar answered Oct 02 '22 15:10

Zain Ullah Muhammad


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"

like image 8
Narendrakumar Avatar answered Oct 02 '22 14:10

Narendrakumar


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.

like image 7
Alex Styl Avatar answered Oct 02 '22 14:10

Alex Styl


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

Go to

File -> Invalidate Caches / Restart...

Solved problem for me

like image 7
MakBeard Avatar answered Oct 02 '22 15:10

MakBeard


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.

like image 6
Florian K Avatar answered Oct 02 '22 15:10

Florian K


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.

like image 6
Blaze Gawlik Avatar answered Oct 02 '22 15:10

Blaze Gawlik


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 :)

like image 6
Andriy Antonov Avatar answered Oct 02 '22 15:10

Andriy Antonov


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.

like image 6
Raj kannan Iyyappan Avatar answered Oct 02 '22 14:10

Raj kannan Iyyappan