我把IntelliJ IDEA从12.0.4升级到12.10。

现在我的Android项目中的所有模块都给出了错误:

错误:没有找到默认活动

我恢复到12.0.4,一切都恢复正常了。

什么好主意吗?我认为这可能是一个丢失插件的问题。由于插件没有安装,它无法找到默认活动。另一个东西可能是本地配置,但我对此表示怀疑。我删除了配置文件夹来验证,这没有改变任何东西。


当前回答

首先,确保清单中包含了默认活动。

例子:

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

如果你已经尝试了所有的方法,但似乎都没有效果

从您的%Home%\删除缓存。Gradle \缓存和同步项目再次。

或者看看这个答案:

Android Studio显示错误的文件内容

其他回答

这个解决方案应该适合你:

进入“编辑配置”。 选择活动,什么都不选择并应用。

正确的方法是将以下内容添加到Manifest文件中:

<activity
    android:name="FULL_NAME_OF_YOUR_ACTIVITY"
    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> </application>

不需要使缓存无效。

我不能评论为什么IntelliJ IDEA的升级会导致这个问题,因为我没有使用它。

然而,这个错误:“Default Activity Not Found”似乎是在告诉你,你没有在文件AndroidManifest.xml中声明一个标记为主活动的活动,在应用程序启动时启动。

你应该至少有一个类似这样的活动:

<activity
        android:name="com.your.package.name.YourActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

如果您至少没有一个带有这样意图过滤器的活动,那么您很可能会看到您在这里包含的错误消息。

您应该将意图过滤器添加到您希望在启动应用程序时打开的Activity中,这应该可以解决您的问题。

额外的细节

(Android Studio 4.1.2)如果项目创建为EmptyApplication,那么开发人员必须手动创建以下三个文件,以避免出现Default Activity Not Found错误:

文件AndroidManifest.xml

文件MainActivity.java

文件activity_main.xml

编辑文件androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.java2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivityName">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

如果你的应用有一个默认的启动活动,这可能是你的错误:

步骤1:选择“编辑配置”

步骤2:注意这个警告:未找到默认活动

第三步:选择一个默认活动

步骤3:保存更改并完成

祝你好运