Installing Kotlin Android project fails with INSTALL_FAILED_DEXOPT

android, android-studio, kotlin

Solution

This occurs when a method name collides with a Kotlin-generated etter, for example:

class Foo(val bar: Any) {
  fun getBar(): Any {}
}

Rename `bar` or `getBar` to something else. For more information see http://youtrack.jetbrains.com/issue/KT-3170

Problem

Attempting to run a Kotlin Android project using Android Studio compiles successfully and generates an APK, but when Studio tries to install the APK on the device the installation fails with `INSTALL_FAILED_DEXOPT`. Looking through logcat I can see messages similar to: ``` 12-13 22:43:57.219: ERROR/dalvikvm(1623): Out-of-order method_idx: 0x2bff then 0x2bff 12-13 22:43:57.219: ERROR/dalvikvm(1623): Trouble with item 897 @ offset 0x13e498 12-13 22:43:57.219: ERROR/dalvikvm(1623): Swap of section type 2006 failed 12-13 22:43:57.219: ERROR/dalvikvm(1623): ERROR: Byte swap + verify failed 12-13 22:43:57.230: ERROR/dalvikvm(1623): Optimization failed ``` The project was converted from Java using the Kotlin IDEA plugin's automatic conversion. There are no compiler warnings.

Original source