androidandroid-studioandroid-manifest

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


Solution

  • 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.