Question
How to Diagnose ':app:compileDebugKotlin' Compilation Errors in Android Gradle Builds
Question
I am getting this Android build error:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
My project uses Gradle and Kotlin in an Android app. Here are the relevant Gradle files.
build.gradle for the app module:
buildscript {
repositories {
maven {
url 'https://jitpack.io'
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android-extensions'
repositories {
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
useLibrary 'org.apache.http.legacy'
lintOptions {
checkReleaseBuilds false
abortOnError false
}
defaultConfig {
applicationId "uxx.xx.xxe"
minSdkVersion 18
targetSdkVersion 25
versionCode 17
versionName "0.1.14"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
ext.enableCrashlytics = false
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
res.srcDirs = ['src/main/res', 'src/main/assets/fonts']
}
}
dexOptions {
jumboMode true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ECLIPSE_.SF'
exclude 'META-INF/ECLIPSE_.RSA'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:cardview-v7:${rootProject.supportLibraryVersion}"
compile "com.google.android.gms:play-services-ads:${rootProject.googlePlayServicesVersion}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'org.igniterealtime.smack:smack-android-extensions:4.1.9'
compile 'org.igniterealtime.smack:smack-tcp:4.1.9'
compile 'org.igniterealtime.smack:smack-experimental:4.1.9'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.getkeepsafe.dexcount'
Top-level build.gradle:
buildscript {
ext.kotlin_version = '1.1.2-2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
ext.googlePlayServicesVersion = '10.2.0'
ext.supportLibraryVersion = '25.3.1'
task clean(type: Delete) {
delete rootProject.buildDir
}
I already tried these steps:
- Invalidate Caches / Restart
- Build -> Clean Project
- Updating the Kotlin plugin and Google APIs
I also ran:
./gradlew build --stacktrace > logs.txt 2>logErrors.txt
The stack trace still ends with:
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
How should I properly diagnose and fix this kind of compileDebugKotlin error in an Android project?
Short Answer
By the end of this page, you will understand what :app:compileDebugKotlin means, why the message Compilation error. See log for more details is usually only a wrapper error, and how to find the real Kotlin compiler message that actually explains the problem. You will also learn how Gradle, the Android plugin, and Kotlin versions work together, what to check in build.gradle, and a practical workflow for fixing build failures in Android projects.
Concept
The main concept behind this error is build troubleshooting in Gradle-based Android projects, especially when Kotlin compilation fails.
The message:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
is usually not the root cause. It means Gradle ran the Kotlin compiler for the debug build of the app module, and that compiler reported an error. Gradle then wraps that compiler failure in a more generic task failure message.
What :app:compileDebugKotlin means
app= the module being builtcompileDebugKotlin= the task that compiles Kotlin code for thedebugvariantExecution failed= that task did not complete successfully
Why this matters
In real Android development, many errors appear as Gradle task failures, but the true problem may be one of these:
- a Kotlin syntax or type error in source code
- a mismatched Kotlin plugin and standard library version
- incompatible Android Gradle plugin, Gradle, or Kotlin versions
- missing dependency or wrong repository
- generated code not being created correctly
- outdated dependency declarations or plugins
The key idea
A often shows , but not . The important part is the , where you usually see file names, line numbers, and actual Kotlin error messages such as:
Mental Model
Think of Gradle as a project manager and the Kotlin compiler as a specialist worker.
- Gradle says: "Compile the Kotlin code for the debug build."
- The Kotlin compiler starts working.
- If it finds a problem, it reports: "I cannot continue."
- Gradle then reports back with a generic message: "The task failed. See the log."
So the Gradle error is like hearing:
"The construction job failed. Ask the electrician for details."
The important information is not that the whole job failed. The important information is the electrician's exact complaint, such as:
- wrong wire connected
- missing component
- incompatible voltage
In Android terms, those become:
- syntax error
- unresolved reference
- incompatible dependency or plugin version
- missing repository or artifact
Syntax and Examples
Core commands for diagnosing the error
Start with commands that show the actual compiler output in the terminal:
./gradlew :app:compileDebugKotlin --info
If that is not enough:
./gradlew :app:compileDebugKotlin --debug
To capture all output, including standard error:
./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1
Notice the difference from this command:
./gradlew build --stacktrace > logs.txt 2>logErrors.txt
That splits normal output and error output into separate files. Kotlin compiler messages may appear in standard output, so you can miss the real message if you only inspect logErrors.txt.
What a useful compiler error looks like
A real Kotlin compile error usually looks more like this:
e: /app/src/main/java/com/example/MainActivity.kt:15:12 Unresolved reference: TextView
That is actionable because it tells you:
- file path
- line number
- column number
- exact reason
Example: generic Gradle failure vs real source-code error
Suppose you have this Kotlin code:
Step by Step Execution
Example debugging workflow
Assume your build fails with:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
Step 1: Run only the failing task
./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1
This narrows the problem to one task and stores all output in one file.
Step 2: Search for the first Kotlin compiler error
Open build-output.txt and look for lines starting with:
e:Unresolved referenceType mismatch- file paths ending in
.kt
Example:
e: /project/app/src/main/java/com/example/LoginActivity.kt:42:23 Unresolved reference: snackbar
Step 3: Ignore the long Gradle stack trace at first
The stack trace tells you the failure moved through Gradle internals:
TaskExecutionExceptionGradleExceptionKotlinCompile
Real World Use Cases
1. Fixing broken Android app builds
This is the most direct use case. When a CI pipeline or local Android Studio build fails, developers need to identify whether the issue is:
- broken Kotlin code
- a missing dependency
- a plugin mismatch
- a repository problem
2. Working with legacy Android projects
Your example uses older Android and Kotlin versions. Many real teams still maintain legacy apps. In those projects, build debugging often involves:
- older support libraries
- deprecated
compiledependencies - Fabric or other old plugins
- older Gradle plugin behavior
Knowing how to read the true compiler error is essential.
3. Continuous Integration failures
On CI servers, you often only see a summary like:
Task :app:compileDebugKotlin FAILED
A developer must then inspect the full logs to find the first real compiler error.
4. Dependency upgrades
After upgrading Kotlin, Android Gradle plugin, or Google libraries, compilation errors can appear because APIs changed or versions are incompatible. The same diagnostic workflow helps isolate whether the break is in code or in configuration.
5. Multi-module Android apps
In bigger codebases, failures may happen in a specific module such as:
:feature-login:compileDebugKotlin
The same rule applies: identify the exact failing task, then inspect the compiler output for that module.
Real Codebase Usage
How developers usually handle this in real projects
Run the smallest failing task first
Instead of rebuilding everything, developers run:
./gradlew :app:compileDebugKotlin
This shortens logs and speeds up debugging.
Use guard-style diagnosis
A common mental checklist is:
- Is there an actual
.ktcompiler error with file and line number? - If not, is a dependency missing?
- If not, are plugin versions compatible?
- If not, is a repository or generated source step broken?
This is similar to a guard clause approach in code: eliminate simple causes first.
Keep versions centralized
Real projects often store versions in one place:
ext.kotlin_version = '1.1.2-2'
ext.supportLibraryVersion = '25.3.1'
This reduces accidental version drift.
Validate dependency setup
Developers commonly check whether the dependency needed by the Kotlin file is actually present. For example, an unresolved class might come from:
- missing library dependency
- wrong artifact version
- repository not declared
Be cautious with broad updates
In legacy projects, upgrading Kotlin alone can break compatibility with:
- Android Gradle plugin
- Gradle wrapper
- old support libraries
Common Mistakes
Mistake 1: Treating the stack trace as the real error
Beginners often focus on lines like:
org.gradle.api.tasks.TaskExecutionException
org.gradle.api.GradleException: Compilation error. See log for more details
These are wrapper errors.
Better approach
Look earlier in the output for:
- file names
- line numbers
e:lines- Kotlin compiler messages
Mistake 2: Redirecting logs in a way that hides the real compiler output
Broken approach:
./gradlew build --stacktrace > logs.txt 2>logErrors.txt
If you only inspect logErrors.txt, you may miss the actual compiler messages.
Better approach
Capture both streams together:
./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1
Mistake 3: Updating one build tool without checking compatibility
For example, changing only Kotlin while leaving an old Android Gradle plugin can create new build issues.
Better approach
Check compatibility among:
- Kotlin Gradle plugin
- Kotlin stdlib
- Android Gradle plugin
Comparisons
| Topic | What it tells you | When to use it | Limitation |
|---|---|---|---|
--stacktrace | Gradle call stack | When a task fails and you want internal failure context | Often does not show the real Kotlin code error by itself |
--info | More build details | Good first step for debugging | Still may be verbose |
--debug | Very detailed logs | Use when --info is not enough | Can be noisy |
Running build | Builds the whole project | Final verification | Too much output for first diagnosis |
Running :app:compileDebugKotlin |
Cheat Sheet
Quick diagnosis checklist
./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1
Then inspect build-output.txt for:
e:lines.kt:file referencesUnresolved referenceType mismatchExpectingCould not resolve
What the error means
Execution failed for task ':app:compileDebugKotlin'
Means:
- module:
app - build variant:
debug - task: compile Kotlin
- status: failed
It does not automatically tell you the root cause.
Best commands
./gradlew :app:compileDebugKotlin
./gradlew :app:compileDebugKotlin --info
./gradlew :app:compileDebugKotlin --debug
./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1
Things to verify in Gradle
FAQ
Why does compileDebugKotlin fail even when Gradle sync succeeds?
Gradle sync checks project configuration and dependencies, but actual compilation happens during build tasks. Kotlin code errors may only appear during compilation.
Is the stack trace enough to fix a Kotlin compilation error?
Usually no. The stack trace shows how Gradle failed. The real cause is often earlier in the log as a Kotlin compiler message.
What is the best command to debug this error?
A good starting point is:
./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1
Then inspect the first actual compiler error in the file.
Can dependency version mismatch cause compileDebugKotlin errors?
Yes. If Kotlin, the Android Gradle plugin, libraries, or repositories are incompatible, the compile task can fail.
Should I run build or :app:compileDebugKotlin first?
Run :app:compileDebugKotlin first. It is smaller, faster, and produces more focused logs.
Why is Compilation error. See log for more details so vague?
Because it is a generic Gradle wrapper message. The detailed reason comes from the Kotlin compiler output earlier in the log.
Can a bad build.gradle repository block cause compilation errors?
Mini Project
Description
Create a small Kotlin command-line project and intentionally trigger a compilation failure, then practice diagnosing it the same way you would diagnose an Android compileDebugKotlin error. This project demonstrates the difference between a generic task failure and the real compiler message that explains what went wrong.
Goal
Learn to capture build output, find the first real compiler error, fix it, and rerun the build successfully.
Requirements
- Create a simple Kotlin project with one file containing a deliberate type error.
- Run the Gradle compile task and save the output to a log file.
- Find the exact compiler message with file and line number.
- Fix the code and rerun the compile task until it succeeds.
Keep learning
Related questions
Accessing Kotlin Extension Functions from Java
Learn how Kotlin extension functions are compiled and how to call them correctly from Java with clear examples and common pitfalls.
Android AlarmManager Example: Scheduling Tasks with AlarmManager
Learn how to use Android AlarmManager to schedule tasks, set alarms, and handle broadcasts with a simple beginner example.
Android Foreground Service Notification Channels in Kotlin
Learn why startForeground fails on Android 8.1 and how to create a valid notification channel for foreground services in Kotlin.