我把IntelliJ IDEA从12.0.4升级到12.10。

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

错误:没有找到默认活动

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

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


当前回答

我在我的代码中发现了这个:

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

如果你仔细看,它应该是<activity android:name="。MainActivity”>。

显然,我在某处重构了一个“活动”,它也改变了AndroidManifest中的名称。

其他回答

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

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

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

我的问题是:

在我的应用程序模块清单,我必须替换另一个依赖模块清单标签。

我在应用程序标签下添加了下面的代码,它为我工作:

tools:replace="android:allowBackup, android:usesCleartextTraffic"

对你来说,这可能是由于一些其他性质。您还必须重写它们。

TL; diana:

确保您不仅检查操作和类别名称,还检查路径。特别是如果你做了重构。

我的解决方案是仔细检查AndroidManifest文件。我做了一个重构,它不仅更新了意图过滤器,而且还更新了意图过滤器名称的路径:

<!-- Type and value were added to the 
     path here when I did the refactor -->
<action android:name="android.intent.type.MAIN"/>
<category android:name="android.intent.value.LAUNCHER"/>

它应该是:

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

去建造。Gradle(项目:xyz)

buildscript {
    repositories {
        jcenter() 
        google()
    }
allprojects {
    repositories {
        jcenter()
        google()
    }

// Just place 'google()' to the top of 'jcenter()'

buildscript {
    repositories {
        google()
        jcenter()
    }
allprojects {
    repositories {
        google()
        jcenter()
    // enter code here
    }
}

它非常适合我。

之前的回答对我没有任何帮助,Android Studio在我之前运行的所有应用程序中都出现了这个问题——所以我知道——这与我的代码无关。

现在我解出来了:

你需要重置Android Studio: 只需转到C:\Users\yourusername\androidStudio3.2(或类似目录)并删除此目录。

这个家伙在他的旧版本的视频中向你展示了如何做到这一点:

如何将Android Studio重置为默认设置?