1

Sometimes I get this error when trying to compile my Android app:
e: Kotlin home does not exist or is not a directory:
FAILURE: Build failed with an exception.

Happens at command line (./gradlew clean build) and in Android Studio 3.0.1. I have done File -> Invalidate Caches / Restart, that does not fix it.

All my Kotlin src is under src/main/java since the majority of the code is still java.

interesting versions / plugins /dependencies:

ext.kotlinVersion = '1.2.21'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

compileSdkVersion 26
buildToolsVersion "26.0.3"
targetSdkVersion 26
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

UPDATE
Found cause of problem. I have multiple Android apps, on different versions of Kotlin. If I build one app, then open another app and try to build it -- kaboom! KotlinCompileDaemon and GradleDaemon processes are specific to just one Kotlin version. The solution is to kill those processes for KotlinCompileDaemon and GradleDaemon. You could use "killall java" as mentioned below, but that kills all of your java processes, which you may not want.

TimCO
  • 131
  • 1
  • 1
  • 14
  • Not just Kotlin. I've had that with Java too. People seem to think we just use one version at a time .... Potentially valuable tools like "profiles" (Netbeans) get glossed over or reinvented by new tools. Can `configurations` help with your specific situation.? – will Mar 21 '18 at 07:58
  • You can look question this answer Referance: https://stackoverflow.com/questions/26422860/android-studio-library-error-package-does-not-exist/60816713#60816713 – Mehmet Agah Balbay Mar 23 '20 at 15:43

1 Answers1

4

There are two things you can try:

  1. Clean your Android studio cache and restart.

  2. Kill KotlinCompileDaemon and GradleDaemon processes and restart gradle:

    kill KotlinCompileDaemon
    kill GradleDaemon
    ./gradlew clean assemble
    

I hope this helps if not feel free to post a comment :)

fibheap
  • 103
  • 1
  • 10
  • thanks for the answer. I put my mac to sleep, came back 5 hours later and no errors. Didn't have to kill any java processes, but next time problem happens I'll try that! – TimCO Feb 21 '18 at 05:13
  • killing the processes worked! If you can edit your answer to remove "killall" and instead just kill KotlinCompileDaemon and GradleDaemon I'll accept your answer. I just don't want people killing java processes that they depend on. – TimCO Feb 21 '18 at 23:36
  • I am glad it worked! Thanks for the update, I have edited the answer – fibheap Feb 23 '18 at 09:03
  • Consider `./gradlew --stop` – gladed Apr 30 '18 at 21:19