3

Below is how this issue manifests if you try to work in the kotlin REPL. However, you see the same issue more directly if you try to run a kotlin main fun from the IDE -- the kotlin classes are not on the classpath. Instead they are in .../app/build/tmp/kotlin-classes/debug. However, they do get put in the dex file.

I am looking at Kotlin for Android, and started with a very simple project (created freshly by Android Studio 3.1.1).

To learn kotlin I wanted to play with a simple .kt class converted from java.

After a rebuild, the Kotlin REPL is started, and this problem happens:

You’re running the REPL with outdated classes: Build module 'app' and restart

Welcome to Kotlin version 1.2.30 (JRE 1.8.0_152-release-1024-b01)
Type :help for help, :quit for quit

import hanafey.com.shoppy.Thing
val x = Thing("a", "b", "c", 1.0)
println(x)
error: unresolved reference: Thing
import hanafey.com.shoppy.Thing

In this case I ignored the "outdated classes" warning because it was not true.

So I believe the IDE and click the provided link to "Build module 'app' and restart". Now it claims another problem:

There were compilation errors in module app
Information:Kotlin: kotlinc-jvm 1.2.30 (JRE 1.8.0_152-release-1024-b01)
Information:4/14/18 7:49 AM - Compilation completed with 1 error and 0 warnings in 889ms
Error:Kotlin: Unsupported plugin option: org.jetbrains.kotlin.android:enabled=true

Am I wrong to think I should be able to fiddle with non-android related kotlin classes in the REPL?

2 Answers 2

0

When AS launches the kotlin REPL it includes the following directory in the classpath which contains the java files:

.../app/build/intermediates/classes/debug

However the kotlin classes are in:

.../app/build/tmp/kotlin-classes/debug

Either the gradle build is not putting the kotlin classes in with the java classes, or the kotlin repl is not started with all of the needed directories on the classpath.

4
  • 1
    Did you find the solution? It is not causing any compilation error in my case, But still, it is showing in REPL and I don't know why.
    – Onkar Nene
    Sep 14, 2018 at 9:53
  • With 3.2 RC3 kotlin classes are available, so the reported problem was fixed. Sep 18, 2018 at 16:06
  • 1
    Larger question is why does "You’re running the REPL with outdated classes: Build module 'app' and restart" appear at all and keep appearing? Click on the "Build module" link and the message just reappears. It's still happening in AS 3.4.1.
    – Phil
    Jun 12, 2019 at 4:16
  • 1
    I faced same issue with Kotlin REPL and clicking "Build module 'app' and restart" would not solve anything and bring me back to same point. Welcome to Kotlin version 1.3.31 (JRE 1.8.0_152-release-1343-b16-5323222). I cleaned the build and started REPL again from tools menu and it asked me for context "Kotlin vs app" and I chose Kotlin and the error is not coming anymore. Aug 5, 2019 at 4:46
0

If i understand correctly, the package hanafey.com.shoppy isn't included and therefore the unresolved reference.

:load /dir/path can be used to import all the packages in dir/path and the following should work.

val x = Thing("a", "b", "c", 1.0) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.