Question

How to Diagnose ':app:compileDebugKotlin' Compilation Errors in Android Gradle Builds

kotlinandroidgradlebuildgradle-kotlin-dsl

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 built
  • compileDebugKotlin = the task that compiles Kotlin code for the debug variant
  • Execution 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 stack trace often shows where Gradle failed, but not why the Kotlin compiler failed. The important part is the compiler output above the stack trace, where you usually see file names, line numbers, and actual Kotlin error messages such as:

Unresolved reference: ...
Type mismatch: inferred type is ... but ... was expected
Expecting a top level declaration

Without that compiler message, the task error alone is too generic to solve.

In this specific Gradle setup

Your Gradle files show an older Android/Kotlin toolchain:

  • Android Gradle plugin 2.3.1
  • Kotlin 1.1.2-2
  • support libraries 25.3.1
  • Google Play Services 10.2.0

That does not automatically prove a version conflict, but it does mean you must be careful about compatibility. Older builds are especially sensitive to mismatched plugin versions, repository issues, and deprecated dependency declarations.

Core lesson

When debugging Android build problems, do not stop at the task failure line. Treat it as a signpost. The real work is to locate the first meaningful compiler error and then check whether it is caused by:

  1. source code
  2. dependency configuration
  3. version compatibility
  4. plugin setup

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
Take Quiz

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:

fun main() {
    val name: Int = "Asha"
    println(name)
}

The Kotlin compiler would report a real error such as:

Type mismatch: inferred type is String but Int was expected

Gradle may then wrap it as:

Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

The second message is just the container. The first message is the real clue.

Example: version consistency in Gradle

A common pattern is to keep Kotlin versions aligned:

buildscript {
    ext.kotlin_version = '1.1.2-2'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

This is good because both the Gradle plugin and Kotlin standard library use the same version variable.

Example: modern dependency style

In older projects you may see:

compile 'org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-2'

In newer Gradle versions, this became:

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

For an old project, changing syntax alone may not fix the build, but understanding which style belongs to which Gradle generation helps avoid accidental incompatibility.

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 reference
  • Type 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:

  • TaskExecutionException
  • GradleException
  • KotlinCompile

That is expected. It does not yet identify the source problem.

Step 4: Fix the actual source or config issue

For example, if the error is:

Unresolved reference: snackbar

you would check:

  • whether the symbol name is correct
  • whether the needed dependency is added
  • whether the import is missing
  • whether generated code exists

Step 5: Rebuild

./gradlew :app:compileDebugKotlin

If that passes, run the larger build:

./gradlew build

Trace example with Kotlin code

Consider this file:

fun greet(user: String) {
    println("Hello, $user")
}

fun main() {
    greet(123)
}

What happens

  1. The compiler reads greet(user: String).
  2. It learns that greet requires a String argument.
  3. It reads greet(123).
  4. It sees 123 is an Int.
  5. It reports a type mismatch.
  6. Gradle marks the Kotlin compile task as failed.
  7. You see the generic compileDebugKotlin error.

That is the same pattern you should expect in Android builds: the task failure is often just the final wrapper around a simpler underlying compiler complaint.

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 compile dependencies
  • 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.

Take Quiz

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:

  1. Is there an actual .kt compiler error with file and line number?
  2. If not, is a dependency missing?
  3. If not, are plugin versions compatible?
  4. 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
  • old third-party plugins like Fabric

In real codebases, upgrades are usually done in compatible groups, not one piece at a time.

Error handling pattern for builds

A practical build-debug pattern is:

  • capture complete logs
  • find the first meaningful error
  • fix one issue at a time
  • rebuild the smallest target
  • only then run the full project build

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
  • Gradle wrapper
  • Android support or AndroidX libraries

Mistake 4: Assuming Gradle config is the only possible cause

Sometimes the problem is just broken Kotlin code.

Broken example:

val count: Int = "five"

This causes a compile error even if Gradle is configured correctly.

Better approach

Always confirm whether the failure is from source code or build configuration.


Mistake 5: Debugging the whole project instead of the failing task

Running full builds creates noisy logs.

Better approach

Use the most specific task possible:

./gradlew :app:compileDebugKotlin

Mistake 6: Ignoring deprecated or unusual Gradle setup

In your app module, this block is suspicious:

buildscript {
    repositories {
        maven {
            url 'https://jitpack.io'
            url 'https://maven.fabric.io/public'
        }
    }
}

A single maven {} block normally expects one url. Writing two url lines in the same block is not a normal repository definition.

Better approach

Declare separate repositories:

buildscript {
    repositories {
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.fabric.io/public' }
    }
}

That may not be the only issue, but malformed Gradle configuration can definitely lead to build problems.

Comparisons

TopicWhat it tells youWhen to use itLimitation
--stacktraceGradle call stackWhen a task fails and you want internal failure contextOften does not show the real Kotlin code error by itself
--infoMore build detailsGood first step for debuggingStill may be verbose
--debugVery detailed logsUse when --info is not enoughCan be noisy
Running buildBuilds the whole projectFinal verificationToo much output for first diagnosis
Running :app:compileDebugKotlinBuilds only the failing Kotlin taskBest first step for this errorOnly helps if that task is truly the failing one
Error typeExampleMeaning
Gradle wrapper errorExecution failed for task ...A task failed, but not necessarily why
Kotlin compiler errorUnresolved reference: XThe actual source or dependency issue
Dependency resolution errorCould not resolve ...Gradle could not download or find a dependency
Plugin compatibility errorfailed to apply pluginA build plugin version or setup problem
Build issue sourceTypical signFix direction
Kotlin source codefile path and line number in .kt fileFix code
Missing import or dependencyUnresolved referenceAdd import or dependency
Version mismatcherrors after upgrade or plugin changesAlign versions
Repository problemCould not resolve or missing artifactFix repositories
Take Quiz

Cheat Sheet

Quick diagnosis checklist

./gradlew :app:compileDebugKotlin --stacktrace > build-output.txt 2>&1

Then inspect build-output.txt for:

  • e: lines
  • .kt: file references
  • Unresolved reference
  • Type mismatch
  • Expecting
  • Could 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

  • Kotlin plugin version matches stdlib version
  • repositories are declared correctly
  • dependencies exist and can be resolved
  • Android Gradle plugin is compatible with Kotlin version
  • only valid repository syntax is used

Suspicious config from the example

maven {
    url 'https://jitpack.io'
    url 'https://maven.fabric.io/public'
}

Prefer:

maven { url 'https://jitpack.io' }
maven { url 'https://maven.fabric.io/public' }

Rule of thumb

  • First meaningful compiler error wins.
  • Fix that one first.
  • Rebuild the smallest failing task.
  • Repeat until clean.

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?

Yes. If dependencies are not resolved correctly because repositories are misconfigured, compilation can fail later when code depends on missing classes.

Take Quiz

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

  1. Create a simple Kotlin project with one file containing a deliberate type error.
  2. Run the Gradle compile task and save the output to a log file.
  3. Find the exact compiler message with file and line number.
  4. Fix the code and rerun the compile task until it succeeds.
Take Quiz

Keep learning

Related questions

View more