简体   繁体   中英

Could not identify launch activity: Default Activity not found after upgrading to Android Studio 4.0

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)

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.

You can solve the problem as follows:

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

    在此处输入图像描述

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

    在此处输入图像描述

For me this was happening in a project in which the main activity was declared in the manifest of an imported module (eg 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>

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.

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.

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

set Launch Options to ( Nothing )

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM