我把IntelliJ IDEA从12.0.4升级到12.10。

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

错误:没有找到默认活动

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

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


当前回答

检查AndroidManifest.xml文件中的应用程序标记中是否存在活动标记。

其他回答

我不能评论为什么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>

我将Intent-filter改为

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

只需要添加DEFAULT选项。我正在使用Process Phoenix库,它提示我定义一个默认意图。这就解决了我的问题。

TouchBoarder几乎做到了。尽管选择“不启动活动”会导致什么都不启动。

在Android Studio中运行/调试配置→Android应用程序→常规→活动→选择“启动”选项:

选择你的活动。这并没有完全修复预期的行为,而是正确地覆盖它。

我的经验:

确保所有Java文件都已标识。如果IntelliJ IDEA没有识别您的Java文件,它就不能理解“Activity”的含义。