32

I'm trying to use the Kotlin REPL within Android Studio.
However, when I open it, I get the following output:

"E:\Program Files\Android\Arctic Fox\android-studio\jre\bin\java.exe" -Dkotlin.repl.ideMode=true -Dfile.encoding=UTF-8 -classpath "E:\Program Files\Android\Arctic Fox\android-studio\lib\idea_rt.jar;C:\Users\me\AppData\Local\Temp\classpath901685403.jar" com.intellij.rt.execution.CommandLineWrapper C:\Users\me\AppData\Local\Temp\classpath901685403.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
`CommandLineWrapper` is ill-suited for launching apps on Java 9+.
If the run configuration uses "classpath file", please change it to "@argfile".
Otherwise, please contact support.

Process finished with exit code 1

The closest solution I've been able to find is this one:
Test framework quit unexpectedly - ClassNotFound Exception
which suggests changing a value in the run configuration, however there doesn't seem to be a run configuration avalible for the REPL.

There is one for "Java Scratch", however changing this does not solve the issue.

I'm using the Arctic Fox Beta (2020.3.1 Beta 5), with version 203-1.5.20-release-289-AS7717.8 of the Kotlin plugin.

Nikunj Paradva
  • 15,332
  • 5
  • 54
  • 65
acrabb3
  • 429
  • 4
  • 5
  • 4
    I have the same issue, for some reason if i start REPL again after it failed (without closing the failed REPL), it now asks for a context module and works. If I open it again, it works. If I close it, then open it again, it fails. – Joozd Sep 25 '21 at 09:39
  • comment from @Joozd is the only way for me to get the repl to work. IntelliJ IDEA 2022.3.2 (Community Edition) – LXJ Feb 08 '23 at 07:58

4 Answers4

39

Keeping the REPL window displaying the above error, again select Tools > Kotlin > Kotlin REPL

A choice is displayed with two items (Project) (Project).app

Select the first option with the name of your project and the REPL starts working.

error message

option after selecting Kotlin REPL again

correctly running REPL

Polymath
  • 630
  • 7
  • 11
17

I changed Run > Edit Configurations... > Templates > Java Scratch > Shorten command line to @argfile (Java 9+) and it fixes the issue.

Android Studio Arctic Fox | 2020.3.1 Build #AI-203.7717.56.2031.7583922, built on July 26, 2021 Runtime version: 11.0.10+0-b96-7249189 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Aleksey
  • 187
  • 1
  • 4
  • 2
    This doesn't work for me. I have **Android Studio Arctic Fox 2020.3.1 Patch 3**. – Kahan Bhalani Jan 03 '22 at 13:10
  • 1
    Worked for me in Bumblebee 2021.1.1: Run>Edit Configurations...>Edit configuration templates...>Java Scratch>Shorten command line:>@argfile (Java 9+) – Phil Jan 31 '22 at 01:06
  • If the steps mentioned in the answer don't work then in the Java Scratch file look for classPath Module and click one of the modules( YOUPROJECTNAME, YOURPROJECTNAME.APP) and then select the @argfile(Java9+) shorten command line for that module . And when you open the REPL choose the module which you selected before when changed its short command line – sharib ahmed Feb 09 '22 at 15:12
  • I really hoped that this work for me, but it didn't unfortunately: /usr/lib/jvm/java-11-openjdk-amd64/bin/java -Dkotlin.repl.ideMode=true -Dfile.encoding=UTF-8 -classpath /home/xxx/android-studio/lib/idea_rt.jar:/tmp/classpath1056675736.jar com.intellij.rt.execution.CommandLineWrapper /tmp/classpath1056675736.jar org.jetbrains.kotlin.cli.jvm.K2JVMCompiler `CommandLineWrapper` is ill-suited for launching apps on Java 9+. If the run configuration uses "classpath file", please change it to "@argfile". Otherwise, please contact support. – LXJ Mar 13 '22 at 09:28
0

I have the same error but eventually fixed it by invalidate caches / restart. Btw I'm using Android Studio Arctic Fox | 2020.3.1 RC 1 and Kotlin plugin version 203-1.5.20-release-289-AS7717.8

saiful
  • 19
  • 4
0

A temporary solution could be if you add the following expression to your gradle.properties file:

android.enableBuildCache=false

After that, Gradle sync (and maybe restarting your IDE) is needed of course.

gabhor
  • 669
  • 9
  • 23