我把IntelliJ IDEA从12.0.4升级到12.10。
现在我的Android项目中的所有模块都给出了错误:
错误:没有找到默认活动
我恢复到12.0.4,一切都恢复正常了。
什么好主意吗?我认为这可能是一个丢失插件的问题。由于插件没有安装,它无法找到默认活动。另一个东西可能是本地配置,但我对此表示怀疑。我删除了配置文件夹来验证,这没有改变任何东西。
我把IntelliJ IDEA从12.0.4升级到12.10。
现在我的Android项目中的所有模块都给出了错误:
错误:没有找到默认活动
我恢复到12.0.4,一切都恢复正常了。
什么好主意吗?我认为这可能是一个丢失插件的问题。由于插件没有安装,它无法找到默认活动。另一个东西可能是本地配置,但我对此表示怀疑。我删除了配置文件夹来验证,这没有改变任何东西。
当前回答
如果您在升级IntelliJ IDEA或Android Studio版本后,或者在生成新的APK文件后,看到该错误发生,您可能需要刷新IDE的缓存。
菜单文件→无效缓存和重启…
其他回答
我尝试了无效缓存和重新启动选项,没有运气。然后我核实了舱单。它正确地设置了主要的活动意图。
我在菜单文件→设置→构建、执行、部署→Gradle的全局Gradle设置下检查了“离线工作”。
我取消了它,修改了构造。gradle文件(项目)使用不同的gradle版本(com.android.tools.build:gradle:3.3.1)并保存它。这触发了Gradle同步。
同步之后,这个错误就消失了。我又可以调试了。
这是在我的电脑意外重启后发生的。奇怪的是,我没有做任何修改,仍然得到这个错误。
以上这些对我都没有帮助。解决我问题的,是这个。
步骤1:
步骤2:
步骤3:
如果这不能解决问题,再试试别的办法。
试1:
菜单文件→无效缓存/重启…
试2:
检查以下两行,
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
在文件manifest.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>
试3:
如图所示: 打开“运行/调试配置”。
如果这也无济于事:
尝试4:
菜单文件→导出到ZIP。
and
将其作为一个新项目导入。
去建造。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 3.5或3.6以来,我开始找不到默认活动,我厌倦了无效缓存和重新启动,重建项目等。
事实证明,我处理多模块和清单的方式是错误的。我有默认的活动的清单在库模块,但它应该已经在两个应用程序模块。
假设库模块 appmodule1 appmodule2
Remove HomeActivity from librarymodule Manifest whatsoever. Add: class AppModuleActivity1 : HomeActivity() to appmodule1 class AppModuleActivity2 : HomeActivity() to appmodule2 To appmodule1 Manifest inside application tag, I added: <activity android:name="com.app.name.AppModuleActivity1"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> Same about appmodule2 but change 2 for 1 in naming.
只是清理和重建。问题就会消失。