8

I have an existing Android Project that uses the following libs:

  1. AutoValue
  2. Dagger2
  3. RxJava
  4. Retrolambda

I am trying to add Kotlin Support so that I can slowly migrate the project over to Kotlin. Here is what I have done.

  1. Added Kotlin dependency.
  2. Converted one of the classes over to Kt class and moved over to src/main/kotlin/..package..

  3. Added kotlin in source set. sourceSets { main.java.srcDirs += 'src/main/kotlin' }

  4. When I do a clean build and deploy the app, I get NoClassDefFoundError exception. However, If I deploy again it works just fine. Any suggestions? I do not have any annotation in the class I converted so I did not apply kapt plugin.

Note: I am using latest kotlin 1.0.4. Also I have instant run disabled.

bond
  • 11,236
  • 7
  • 48
  • 62
  • you might want to report this to [the Kotlin issue tracker](http://kotl.in/issue) because it seems more like something that needs triage and potentially reporting as a bug. – Jayson Minard Sep 23 '16 at 16:38
  • Do you use any generated classes in your new .kt file? Probably in time of kotlin compilation this class isn't exists. – lllyct Aug 14 '17 at 21:01

3 Answers3

4

Go to Files > Settings and turn off completely Instant Run, I mean all checkboxes should be unchecked.

Clean and rebuild project.

Then it should work

Edit: As you said that Instant is disabled - using protip check your configuration and update Gradle and Android Studio if you're not using the latest.

According to this issue, changing Gradle plugin version from 2.10 to 2.14.1 may help.

Protip: Use combination Ctrl+Shift+A to find commands like

  • Configure Kotlin in Project

  • Configure Kotlin Updates

  • Convert Java File to Kotlin

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
0

first you need to configure you android studio with kotlin , for this need to add kotlin plugin in android studio, and then need to add dependencies and then convert java classes to kotlin please have look this video.

https://www.youtube.com/watch?v=DN2EDdycZ3c

Lovekush Vishwakarma
  • 3,035
  • 23
  • 25
0

Suffix the Kotlin classes with kt when calling them from Java.

Otherwise add @file:JvmName("Utils") before the package in the Kotlin class if you must call it in java with whatever custom name you wish like Utils in this case.

more details can be found here

tima
  • 1,498
  • 4
  • 20
  • 28
AyoGitNg
  • 530
  • 5
  • 9