我把IntelliJ IDEA从12.0.4升级到12.10。
现在我的Android项目中的所有模块都给出了错误:
错误:没有找到默认活动
我恢复到12.0.4,一切都恢复正常了。
什么好主意吗?我认为这可能是一个丢失插件的问题。由于插件没有安装,它无法找到默认活动。另一个东西可能是本地配置,但我对此表示怀疑。我删除了配置文件夹来验证,这没有改变任何东西。
我把IntelliJ IDEA从12.0.4升级到12.10。
现在我的Android项目中的所有模块都给出了错误:
错误:没有找到默认活动
我恢复到12.0.4,一切都恢复正常了。
什么好主意吗?我认为这可能是一个丢失插件的问题。由于插件没有安装,它无法找到默认活动。另一个东西可能是本地配置,但我对此表示怀疑。我删除了配置文件夹来验证,这没有改变任何东西。
当前回答
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"/>
其他回答
首先,确保清单中包含了默认活动。
例子:
<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显示错误的文件内容
我将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库,它提示我定义一个默认意图。这就解决了我的问题。
在Android Studio中运行/调试配置-> Android应用程序->通用->活动->选择“不启动活动”选项。
编辑文件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>
在我的例子中,我重构了一个名为“activity”的成员变量。我把它重命名为“context”…
我发现重构是对清单中的活动标记进行的,我发现它们是上下文标记……这是非常愚蠢的Android Studio方面!