Gradle cannot find KotlinCompile.getDestinationDir() during the build
Unable to find method 'java.io.File org.jetbrains.kotlin.gradle.tasks.KotlinCompile.getDestinationDir()'Short answer
This is a version mismatch, not a code bug. The Kotlin Gradle plugin, Gradle and the Android Gradle plugin must sit inside the compatibility ranges that Kotlin publishes. Find the Kotlin plugin row that covers your Gradle and AGP versions, then upgrade the plugin or the tools until all three fit one row.
Fix it fast
1Find out which cause you have
Write down the three versions in play: the Kotlin plugin, Gradle and the Android Gradle plugin. Then compare them with the compatibility table in the Kotlin documentation.
./gradlew --version grep -rn "org.jetbrains.kotlin\|com.android.application" --include=*.gradle --include=*.kts --include=*.toml .2Match what you see, then jump to its fix
- 1
The build broke after upgrading Gradle or the wrapper, and the Kotlin plugin version did not changeThe Kotlin Gradle plugin is too old for the Gradle versionFix - 2
AGP was upgraded (or Android Studio updated the project), and the Kotlin plugin stayed behindThe Android Gradle Plugin is outside the range of the Kotlin pluginFix
- 1
What does the error look like?
Unable to find method 'java.io.File org.jetbrains.kotlin.gradle.tasks.KotlinCompile.getDestinationDir()'
Cause 1 of 2
The Kotlin Gradle plugin is too old for the Gradle version
1Check
Kotlin publishes a minimum and maximum Gradle version for every plugin release. For example, plugin 1.8.0 to 1.8.11 is listed for Gradle 6.8.3 to 7.3.3, and 1.9.20 to 1.9.25 for 6.8.3 to 8.1.1. A Gradle version outside the range of your plugin is not supported.
./gradlew --version | grep Gradle2Fix
Raise the Kotlin plugin to a release whose Gradle range includes your Gradle, for example 2.2.0 to 2.2.10 for Gradle 8.14, then rebuild.
// gradle/libs.versions.toml
kotlin = "2.1.21"
// or settings/plugins block
// id("org.jetbrains.kotlin.android") version "2.1.21" apply false3Verify
Run the build; the method error is gone.
./gradlew clean assembleDebugConfirmed by kotlinlang.org
Cause 2 of 2
The Android Gradle Plugin is outside the range of the Kotlin plugin
1Check
The same table lists an AGP range for each Kotlin plugin release; 1.9.20 to 1.9.25 covers AGP 4.2.2 to 8.1.0, and 2.1.0 to 2.1.10 covers 7.3.1 to 8.7.2.
grep -rn "com.android.application" --include=*.gradle --include=*.kts --include=*.toml .2Fix
Choose the Kotlin release whose row includes both your Gradle and your AGP version, or move AGP down to that row. Newer versions than the table's maximum may work, but they are not guaranteed.
// pick one row, for example Kotlin 2.1.21 with AGP 8.7.2 and Gradle 8.12.13Verify
Sync and build again after aligning the versions.
./gradlew clean assembleDebugConfirmed by kotlinlang.org
How do I stop it coming back?
- Upgrade Kotlin, AGP and Gradle together, and check the Kotlin compatibility table first.
- Keep all three versions in one place (a version catalog) so a mismatch is visible in review.
- Run clean assembleDebug in CI after any version bump.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
AGPBI D8 error from com.android.tools.r8.kotlin during an Android build
AGPBI: {"kind":"error","text":"com.android.tools.r8.kotlin.H","sources":[{}],"tool":"D8"}
D8 and R8 read Kotlin metadata, and each Kotlin version needs a minimum Android Gradle Plugin.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fixMobile apps
Java and Kotlin compile to different JVM targets in an Android module
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17)
Java and Kotlin tasks in the same module are compiling for different JVM targets, for example 1.8 and 17.
2 causes, each with a fix