本文翻译自:“Default Activity Not Found” on Android Studio upgrade
I upgraded IntelliJ Idea from 12.0.4 to 12.10. 我将IntelliJ Idea从12.0.4升级到12.10。
Now all the modules in my Android project give the error: 现在,我的Android项目中的所有模块都给出了错误:
Error: Default Activity Not Found 错误:找不到默认活动
I reverted back to 12.0.4 and it everything works again. 我回到了12.0.4,一切又恢复了。
Any ideas? 有任何想法吗? I think it might be an issue with a missing plugin. 我认为这可能是缺少插件的问题。 Since the plugin is not installed, it is not able to find the default activity. 由于未安装该插件,因此无法找到默认活动。 Another thing could have been a local config, but I doubt it. 另一件事可能是本地配置,但我对此表示怀疑。 I deleted the configuration folder to verify and that didn't change anything. 我删除了配置文件夹以进行验证,但没有进行任何更改。
#1楼
参考:https://stackoom.com/question/14OpF/Android-Studio升级中的-未找到默认活动
#2楼
I can't comment on why the upgrade of IntelliJ might cause this problem because I don't use it. 我无法评论为什么IntelliJ升级可能会导致此问题,因为我不使用它。
However, that error: "Default Activity Not Found" seems to be telling you that you don't have an activity declared in AndroidManifest.xml that is marked as the main activity, to be launched when the application starts. 但是,该错误:“未找到默认活动”似乎是在告诉您您没有在AndroidManifest.xml中声明的活动被标记为主要活动,该活动将在应用程序启动时启动。
You should have at least one activity that looks something like this: 您应该至少有一个看起来像这样的活动:
<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>
If you don't have at least one activity with an intent filter like that, you would most likely see the error message you have included here. 如果您没有至少一个活动具有这样的意图过滤器,则很可能会看到此处包含的错误消息。
You should add that intent filter to the Activity that you wish to open when you start the application, and that should fix your problem. 您应该在启动应用程序时将该意图过滤器添加到希望打开的活动中,这样可以解决您的问题。
#3楼
如果您在升级IntelliJ IDEA或Android Studio的版本后,或在生成新的APK之后看到错误,则可能需要刷新IDE的缓存。
File -> Invalidate Caches / Restart...
#4楼
Try to right click on the project and choose Open Module Settings . 尝试右键单击该项目,然后选择“ 打开模块设置” 。 Then go to the Sources tab in your module, find the src folder, right click on it and mark it as Sources (blue color). 然后转到模块中的“ 源”选项卡,找到src文件夹,右键单击它并将其标记为“ 源” (蓝色)。
EDIT: There is no sources tab in later versions of Android Studio, but you can edit the build.gradle file instead: https://stackoverflow.com/a/22028681/1101730 编辑:更高版本的Android Studio中没有源选项卡,但您可以改为编辑build.gradle文件: https : //stackoverflow.com/a/22028681/1101730
#5楼
-
Build -> Rebuild Project
-
File -> Invalidate Caches.. -> Invalidate and restart
It works for me. 这个对我有用。 Rebuild project to make sure that no errors in project. 重建项目以确保项目中没有错误。 Then we can invalidate cache. 然后我们可以使缓存无效。
#6楼
I started with a demo app and modified it. 我从演示应用程序开始,然后对其进行了修改。 I change the java path inside source from com -> example -> foo to my own and edited the manifest; 我将源内部的java路径从com-> example-> foo更改为自己的路径,并编辑了清单; however, Android Studio (0.8.7) got very confused. 但是,Android Studio(0.8.7)感到非常困惑。
I tried everything listed above and none of it worked for me. 我尝试了上面列出的所有内容,但没有一个对我有用。 Maybe it even made things worse? 也许甚至使情况变得更糟?
My final solution was to edit <projectname>.iml
in the .idea
subdirectory by opening it up in Android Studio (aka text editor). 我的最终解决方案是通过在Android Studio(又称为文本编辑器)中打开.idea
子目录中的<projectname>.iml
来对其进行编辑。
Before: 之前:
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
I (re)added the src directory (2nd line). 我(重新)添加了src目录(第二行)。 After: 后:
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
After saving it, Android Studio reloaded and started functioning as expected. 保存后,Android Studio重新加载并开始按预期运行。