14

I've been having this problem since upgrading to Android Studio 4.0 on macOS. When I try to start my app from Android Studio, I get the following error:

Could not identify launch activity: Default Activity not found
Error while Launching activity

What's a bit unique about my project is that the default activity is defined in the manifest of another library used by my project, not the project itself. This was all working fine before the upgrade, but now it isn't for me. When I open the project containing the dependency, it builds and runs fine. I've already tried the following steps:

  • clean the project, rebuild
  • invalidate caches and restart
  • reinstall Android Studio
  • delete all generated files and folders (build, gradle, .idea, etc)
user2970752
  • 201
  • 1
  • 2
  • 5
  • Add you layout code – MexiCano Jun 03 '20 at 16:17
  • Looks like a problem in the manifest. I think you should post it – Yaroslav Jun 03 '20 at 16:27
  • 2
    This might be a AS issue. I've seen a few reports on the issuetracker while reporting issue i found in the Canary version: https://issuetracker.google.com/issues/158019870 . You can try to report it as well, with logs so you can get a fix for it. – Mihai Neacsu Jun 03 '20 at 17:04
  • 2
    Thanks, I'm convinced that it's a bug. I've reverted to AS 3.6.3 and don't have the problem anymore. I've starred the issue, hopefully it'll get fixed soon! – user2970752 Jun 03 '20 at 22:43
  • I had the same problem in my Android Studio 4.0, my team members did not have any such issues, they were on older version of AS. Hence for the time being I have reverted back to AS 3.6.3 and the problem is gone. As the issue tracker suggests the bug will be gone in 4.0.1 or later but for the time being we will just have to downgrade AS – ravi Jul 13 '20 at 05:54
  • In my case after trying so many solutions, it was a silly mistake. Somehow an activity(not main activity) got registered twice in the Manifest. Once I removed the duplicate, the app run with no problem. – Sam Aug 14 '20 at 19:32

7 Answers7

7

You can solve the problem as follows:

  1. Click your Module Selection window,then click Edit Configurations…

    enter image description here

  2. Then set Launch Options to Nothing; that's okay:

    enter image description here

Community
  • 1
  • 1
chaoqiang li
  • 111
  • 2
  • 6
    Of course this removes the error, but then when you run the configuration NOTHING runs...this is not an acceptable solution, this is just diverting the problem elsewhere. – topher217 Sep 17 '20 at 06:19
5

To dovetail off of Mike N.'s comment, it looks like it is an issue to be resolved in the next point release: https://issuetracker.google.com/issues/158019870

For the details of the quick fix, for me I looked at the Merged Manifest tab, which is at the bottom-left of the AndroidManifest.xml pane. This shows all of the library manifests combined with your activity's.

The dialog said an error occurred where browser:1.0.0 manifest had a minSdk of 15 whereas all the rest of my minSdk are 14. I clicked on:

use a compatible library with a minSdk of at most 14, or increase this project's minSdk version to at least 15.

Which brought up my minSdk to 15, and the error with the launcher went away, it will now insta-launch on my device. So I would sit tight for AS 4.0.1 but in the meantime, check the Merged Manifest.

A13X
  • 409
  • 1
  • 6
  • 27
  • Thanks I had no idea that tool/tab even existed! – topher217 Sep 17 '20 at 07:06
  • 1
    It wasn't 100% clear to me either at first that manifest files get merged. Apparently you can configure quite a lot: https://developer.android.com/studio/build/manifest-merge – A13X Sep 22 '20 at 23:32
4

For me this was happening in a project in which the main activity was declared in the manifest of an imported module (e.g. not in "app" module).

The solution for me was to add again the activity declaration in the manifest file of my top project:

<activity android:name="com.cristian_slav.elements.MainActivity"
          android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
  • I had the main activity declared in the build flavors own manifest. Moving it to top manifest as suggested fixed my project in AS 4.0.1. – Scam Aug 07 '20 at 06:48
1

On my side it was a issue with the manifest. You can detect this type of issue by watching the merged manifest tab. For more details you can watch the link shared by Mike N. in the first comment.

Lu No
  • 51
  • 5
0

The problem will arise in new projects when one forgets to tick the default activity checkbox during adding anyone of the first or subsequent new activity.

This can be rectified at later stage by going to Run> Edit Configurations > Launch : in which change to specified activity and select the activity you choose to keep as the first page on launch of app.

Karthick
  • 1
  • 1
0

Try these steps:

  1. Close Android Studio
  2. Go to

C:\Users\my_user_name.AndroidStudio4.0\system\caches

  1. Delete "caches" folder
  2. Relaunch Android Studio
Vikrant_Dev
  • 430
  • 2
  • 15
-1

set Launch Options to (Nothing)

enter image description here

4b0
  • 21,981
  • 30
  • 95
  • 142