简体   繁体   English

无法识别启动活动:未找到默认活动

[英]Could not identify launch Activity: Default Activity not found

I'm new to android and I have encounterded a problem.我是android新手,遇到了一个问题。 The console said that "Could not identify launch activity: Default Activity not found".控制台说“无法识别启动活动:未找到默认活动”。 I have add我已经添加

<intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

in manifests.在清单中。 And I have tried Invalidate caches/Restart,still not worked.而且我已经尝试过使缓存无效/重新启动,但仍然没有用。 And the class file which contains the main activity turn green in android studio.并且包含主要活动的类文件在android studio中变为绿色。 I don't know what that means.我不知道那是什么意思。 This is my manifests file.这是我的清单文件。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mrrobot.mycoolweather" >
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <Activity       android:name="com.example.mrrobot.mycoolweather.activity.ChooseAreaActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </Activity>
</application>

</manifest>

The chooseAreaActivity is the one I want to use as launcher activity. chooseAreaActivity 是我想用作启动器活动的活动。 在此处输入图像描述

For main activity in your manifest you have to add this with category LAUNCHER (First Activity on launch app):对于清单中的主要活动,您必须将其添加到类别LAUNCHER (启动应用程序上的第一个活动):

<activity
    android:name=".MainActivity"
    android:label="YourAppName"
    android:theme="@style/AppTheme.NoActionBar" >
      <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
</activity>

For other activity you have to change category to DEFAULT :对于其他活动,您必须将类别更改为DEFAULT

<activity
    android:name=".OtherActivity"
    android:theme="@style/AppTheme.NoActionBar" >
    <intent-filter>
            <action android:name="package.OtherActivity" />

            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Check this Activity and this Start Another Activity检查这个活动和这个开始另一个活动

So your code is:所以你的代码是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mrrobot.mycoolweather" >
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".activity.ChooseAreaActivity"
        android:label="@string/app_name" >
          <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
    </activity>
</application>

</manifest>

Sometimes it is solved just restarting Android Studio有时只需重新启动 Android Studio 即可解决

单击“文件”,然后单击“使缓存无效”


I had the "Default Activity not found" problem a couple of times and I could solved restarting my android Studio.我有几次“未找到默认活动”问题,我可以解决重新启动我的 android Studio 的问题。

Although the question is kind of outdated, I would add the following to all the given answers:虽然这个问题有点过时,但我会在所有给定的答案中添加以下内容:

For multi-module projects check carefully that you modify the Manifest corresponding to the Configuration you are trying to run.对于多模块项目,请仔细检查您是否修改了与您尝试运行的Configuration相对应的Manifest

Had the same problem and spent 20 minutes just to discover that I was trying to run wrong configuration (with an Application in ModulbeB , while thinking that I was running one from ModuleA ).遇到了同样的问题,花了 20 分钟才发现我试图运行错误的配置(在ModulbeB中有一个Application ,同时认为我正在从ModuleA运行一个)。

And sometimes you are working on other module default runnable module changes so you have to change it.有时您正在处理其他模块默认可运行模块更改,因此您必须更改它。 在此处输入图像描述

如果您在升级 IDEA、升级 Android Studio 版本或生成新 APK 后发现该错误,您可能需要刷新 IDE 的缓存。

File -> Invalidate Caches / Restart...

In your manifest file there was wrong element name (Activity change to activity) declared在您的清单文件中声明了错误的元素名称(活动更改为活动)

<Activity       android:name="com.example.mrrobot.mycoolweather.activity.ChooseAreaActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </Activity>

Change it to:将其更改为:

 <activity       android:name="com.example.mrrobot.mycoolweather.activity.ChooseAreaActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

i had these issues with my project:我的项目有这些问题:

  • Default activity not found未找到默认活动

  • xml intellisense was not working xml 智能感知不工作

  • kotlin standard functions were not detecting kotlin 标准函数未检测到

All my above issues were resolved by Deleting System cache of Android Studio 3.3 at the home path, and it's working nicely for me,, Steps:我上面的所有问题都通过在主路径中删除 Android Studio 3.3 的系统缓存来解决,它对我来说很好,步骤:

  1. exit Android Studio退出 Android Studio

  2. Go to path > C:\Users\YOUR_WINDOW_USER_NAME.AndroidStudio3.3\system转到路径 > C:\Users\YOUR_WINDOW_USER_NAME.AndroidStudio3.3\system

  3. Then you have a \caches folder, delete this caches folder然后你有一个 \caches 文件夹,删除这个缓存文件夹

  4. Now open Android Studio and load your project现在打开 Android Studio 并加载您的项目

Worked for me.. i wasted couple of hours resolving this issue and finally it got resolved in this way.为我工作..我浪费了几个小时来解决这个问题,最后它以这种方式得到了解决。

Exit your android studio IDE.退出你的 android studio IDE。 Then locate the "caches" folder in .AndroidStudio3.2 folder.然后在 .AndroidStudio3.2 文件夹中找到“caches”文件夹。

Location地点

C:\Users\YOUR_USERNAME\.AndroidStudio3.2\system\caches C:\Users\YOUR_USERNAME\.AndroidStudio3.2\system\caches

For example.例如。

Let's assume say YOUR_USERNAME is called Admin.假设说 YOUR_USERNAME 被称为 Admin。

C:\Users\Admin\.AndroidStudio3.2\system\caches C:\Users\Admin\.AndroidStudio3.2\system\caches

Delete the caches folder and start your android studio IDE.删除缓存文件夹并启动您的 android studio IDE。

I have tried solutions here and other questions我在这里尝试过解决方案和其他问题

  • clean & rebuild & invalidate and restart清理 & 重建 & 无效并重新启动
  • make sure that activity has LAUNCHER as category确保活动将 LAUNCHER 作为类别
  • delete Android cache folder删除 Android 缓存文件夹

at End, activity tag was has <activity android:name="com.exmaple.todo.MainActivity" /> when i changed it to <activity android:name=".MainActivity" /> app worked.最后,活动标签有<activity android:name="com.exmaple.todo.MainActivity" />当我将其更改为<activity android:name=".MainActivity" />应用程序工作。

I hope it help you if other solution not work.如果其他解决方案不起作用,我希望它对您有所帮助。

If your activity is in a different module (eg ':library) und you forgot to specify the subproject in the dependencies{} scriptblock of your :app module, the manifest of :library and therefore the activities it declares, are not imported.如果您的活动位于不同的模块中(例如 ':library),并且您忘记在 :app 模块的 dependencies{} 脚本块中指定子项目,则不会导入 :library 的清单以及它声明的活动。

dependencies {
   api project (':library')

You may check whether all activities show up in your app-debug.apk by using the following Android Studio menu command:您可以使用以下 Android Studio 菜单命令检查是否所有活动都显示在您的 app-debug.apk 中:

->Build->Analyze APK->app-debug.apk ->构建->分析APK->app-debug.apk

Now open the AndroidManifest.xml and check its activity declarations.现在打开 AndroidManifest.xml 并检查其活动声明。

When I upgraded Android Studio to 2021.1.1.23 somehow my Run Configuration was switched from app to models , producing this error.当我以某种方式将 Android Studio 升级到2021.1.1.23时,我的运行配置从app切换到models ,产生了这个错误。 Switching back to app resolved the issue for me.切换回app为我解决了这个问题。

My main activity was not declared in Android Manifest File.我的主要活动未在 Android 清单文件中声明。 That's the reason which came that error.这就是出现该错误的原因。 This error come because of a declaration problem of Android Manifest file.出现此错误是因为 Android Manifest 文件的声明问题。 Please check it.请检查一下。 :D :D

This happened to me aswell took me ages to figure out why, but a weird bug I spotted is that if you run the app with breakpoints in your code without debugging mode it will cause this error to happen.这也发生在我身上,我花了很长时间才弄清楚原因,但我发现的一个奇怪的错误是,如果你在没有调试模式的情况下在代码中运行带有断点的应用程序,则会导致此错误发生。

Quick fix for now: Only use breakpoints for degbugging mode.现在快速修复:仅将断点用于调试模式。

Check your duplicate initialize activity in your AndroidManifest.xml检查您的 AndroidManifest.xml 中的重复初始化活动

Like bellow:像下面这样:

        <activity android:name=".nim.qiaqia.lota.LotaProduct"/>
        <activity android:name=".nim.qiaqia.lota.LotaOrderDetail"/>
        <activity android:name=".nim.qiaqia.main.activity.RechargeListLotaActivity"/>
        <activity android:name=".nim.qiaqia.lota.MiningCoinLota"/>
        <activity android:name=".nim.qiaqia.lota.LotaOrderDetail"/>

that can causes ""Default Activity not found" also. So, remove it and see. its works! :)这也可能导致“未找到默认活动”。因此,将其删除并查看。它的工作原理!:)

In my case android manifest was correct .在我的情况下,android manifest 是正确的。 I tried to invalidate Caches and restart but not worked.我试图使缓存无效并重新启动,但没有奏效。 Then Rebuild project and it also did not work.然后重建项目,它也没有工作。

Then I realized that last night I added a new library to build Gradle, it was this: implementation 'com.yalantis:eqwaves:1.0.1' And after removing this everything worked fine.然后我意识到昨晚我添加了一个新库来构建 Gradle,它是这样的: implementation 'com.yalantis:eqwaves:1.0.1'删除它之后一切正常。

TIP: "Always have a track of things you do in your project, otherwise you will end up wasting your time"提示: “始终跟踪您在项目中所做的事情,否则您最终会浪费时间”

If you only enabled building the app via app bundle, then this error might also occure when you try installing it as a default APK.如果您只启用了通过 app bundle 构建应用程序,那么当您尝试将其安装为默认 APK 时也可能会出现此错误。 Change the deployment option to APK from App Bundle and you are good to go.将部署选项从 App Bundle 更改为 APK ,一切顺利。

I got this error in android 12+ after changing launch activity adding intent-filter but not make it exported.在更改启动活动添加intent-filter但未将其导出后,我在 android 12+ 中收到此错误。
so not forget.所以不要忘记。

           
android:exported="true"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法识别启动活动:未找到默认活动 - Could not identify launch Activity: Default Activity wasn't found 自定义键盘-无法识别启动活动:找不到默认活动 - Custom Keyboard - Could not identify launch activity: Default Activity not found Android Automotive:无法识别启动活动:未找到默认活动 - Android Automotive: Could not identify launch activity: Default Activity not found 我经常发现此特定错误:“无法识别启动活动:找不到默认活动启动活动时出错” - I often found this specific error: “Could not identify launch activity: Default Activity not found Error while Launching activity” 无法识别启动活动:找不到默认活动启动活动时出错 - Could not identify launch activity: Default Activity not found Error while Launching activity 无法识别启动活动,未找到默认活动启动活动时出错 - Could not identify launch activity , Default Activity not found Error while Launching activity 无法识别启动活动:升级到 Android Studio 4.0 后未找到默认活动 - Could not identify launch activity: Default Activity not found after upgrading to Android Studio 4.0 在构建Kotlin项目时,Android Studio报告“无法识别启动活动:找不到默认活动” - Android Studio reports “Could not identify launch activity: Default Activity not found” when building Kotlin projects 运行项目时出现错误(无法识别启动活动:未找到默认活动) - Getting Error(Could not identify launch activity: Default Activity not found) While running project “无法识别启动活动:未找到默认活动” - Android Studio - 没有答案工作 - "Could not identify launch activity: Default Activity not found" - Android Studio - no answers working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM