简体   繁体   中英

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. When I select "Run" in Android Studio I get the error:

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.

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. 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.

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. Here's how the one from android-anko-sample looks:

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.

How do I fix this issue?

I'm using:

  • Android Studio 2.1.2
  • Ubuntu Linux 16.04
  • 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:

This was caused by not having the Kotlin plugin installed in Android Studio.

To fix, go to File → Settings → Plugins → Browse Repositories, find "Kotlin", and install it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM