我把IntelliJ IDEA从12.0.4升级到12.10。

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

错误:没有找到默认活动

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

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


当前回答

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

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

其他回答

使缓存失效/重新启动



之后,你的应用程序必须运行!

虽然很丑,但对我很管用:

我有这个错误消息,我的问题是在一个模块。我只是删除了应用程序标签完全从我的模块的清单和它工作。

(同时从模块库中删除ic_launcher。)

它是:

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

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="23"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name="com.example.mymodule.MainActivity"
            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>

Now:

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

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="23"/>

</manifest>

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

菜单文件→无效缓存和重启…

我的经验:

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

我也遇到过同样的问题。由于某些原因,Android Studio将大部分XML文件中的所有Android:name属性(包括manifest)替换为Android:subject (Android Studio无法识别)。

正如你在上图中看到的,IDE不识别android:subject属性。因此,它将无法读取指定mainactivity的行。

解决方案是简单地改变每个android:受制于android:name,然后从Build菜单中重建项目*→重建项目。在重新构建项目时,您可能会遇到相同的问题,因此执行与上面相同的操作。