简体   繁体   English

在构建Kotlin项目时,Android Studio报告“无法识别启动活动:找不到默认活动”

[英]Android Studio reports “Could not identify launch activity: Default Activity not found” when building Kotlin projects

I'm trying to build an Android app using Kotlin and Anko. 我正在尝试使用Kotlin和Anko构建一个Android应用程序。 When I select "Run" in Android Studio I get the error: 当我在Android Studio中选择“运行”时,出现错误:

Could not identify launch activity: Default Activity not found 无法识别启动活动:找不到默认活动
Error while Launching activity 启动活动时出错

and the app does not start. 并且该应用程序无法启动。 I get this error with both the emulator and with a real phone. 我在模拟器和真实手机上都遇到此错误。

To try and narrow down the problem I tried a couple of sample Anko projects, including android-anko-sample , and they all exhibit this same broken behavior. 为了缩小问题的范围,我尝试了几个示例Anko项目,包括android-anko-sample ,它们都表现出相同的损坏行为。

I have other Android projects I've written in Java, and they run without this problem, which suggests that this is somehow a Kotlin or Anko specific issue. 我还有其他用Java写过的Android项目,它们运行时都没有这个问题,这表明这是Kotlin或Anko特有的问题。 I can even switch back and forth between one of my Java apps and the "android-anko-sample" app linked above, and reproduce the problem with android-anko-sample consistently, while my Java app works correctly every time. 我什至可以在我的Java应用程序之一和上面链接的“ android-anko-sample”应用程序之间来回切换,并始终如一地重现android-anko-sample的问题,而我的Java应用程序每次都能正常运行。

I have looked at other questions involving this error message, and the solutions posted were either not applicable or didn't help. 我查看了与此错误消息有关的其他问题,并且发布的解决方案不适用或无济于事。

One thing I have noticed that's weird is that when I open AndroidManifest.xml (of any of these Anko apps) in Android Studio the names of the activities are shown in red, as if they are errors. 我注意到的一件奇怪的事是,当我在Android Studio中打开(这些Anko应用程序中的任何一个) AndroidManifest.xml时,活动的名称显示为红色,就好像它们是错误的一样。 Here's how the one from android-anko-sample looks: 这是android-anko-sample的外观:

AndroidManifest.xml的屏幕截图

Note that the app does get installed on the phone/emulator, and I can tap on the icon and run it. 请注意,该应用程序确实已安装在手机/模拟器上,我可以点击该图标并运行它。 It just won't automatically start when I select run from Android Studio, which is pretty inconvenient. 当我选择从Android Studio运行时,它不会自动启动,这非常不方便。

How do I fix this issue? 如何解决此问题?

I'm using: 我正在使用:

  • Android Studio 2.1.2 Android Studio 2.1.2
  • Ubuntu Linux 16.04 Ubuntu Linux 16.04
  • Oracle JDK 1.8.0_131-b11 Oracle JDK 1.8.0_131-b11

Code is here: 代码在这里:

The complete contents of a few of Android Studio's panes are available in this gist: 此要点提供了一些Android Studio窗格的完整内容:

This was caused by not having the Kotlin plugin installed in Android Studio. 这是由于未在Android Studio中安装Kotlin插件引起的。

To fix, go to File → Settings → Plugins → Browse Repositories, find "Kotlin", and install it. 要解决此问题,请转到文件→设置→插件→浏览存储库,找到“ Kotlin”,然后安装它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Automotive:无法识别启动活动:未找到默认活动 - Android Automotive: Could not identify launch activity: Default Activity not found 无法识别启动活动:未找到默认活动 - Could not identify launch Activity: Default Activity not found 无法识别启动活动:升级到 Android Studio 4.0 后未找到默认活动 - Could not identify launch activity: Default Activity not found after upgrading to Android Studio 4.0 “无法识别启动活动:未找到默认活动” - Android Studio - 没有答案工作 - "Could not identify launch activity: Default Activity not found" - Android Studio - no answers working 无法识别启动活动:未找到默认活动 - Could not identify launch Activity: Default Activity wasn't found 自定义键盘-无法识别启动活动:找不到默认活动 - Custom Keyboard - Could not identify launch activity: Default Activity not found 我经常发现此特定错误:“无法识别启动活动:找不到默认活动启动活动时出错” - I often found this specific error: “Could not identify launch activity: Default Activity not found Error while Launching activity” 无法识别启动活动:找不到默认活动启动活动时出错 - Could not identify launch activity: Default Activity not found Error while Launching activity 无法识别启动活动,未找到默认活动启动活动时出错 - Could not identify launch activity , Default Activity not found Error while Launching activity 无法识别启动活动 - Could not identify launch Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM