Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin class NoClassDefFoundError crash

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.

like image 420
bond Avatar asked Sep 23 '16 16:09

bond


1 Answers

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

like image 123
piotrek1543 Avatar answered Oct 30 '22 20:10

piotrek1543