You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows下Dagger生成组件无法识别Kotlin类编译失败问题

Fixing Dagger's "Cannot Find Symbol" Error for Kotlin Classes on Windows

I’ve run into this exact Windows-specific Dagger+kapt issue before, and it almost always boils down to filesystem quirks or misconfigured build tools that play nice on case-sensitive systems (Mac/Linux) but break on Windows’ case-insensitive setup. Here’s how to tackle it step by step:

1. Fix Case Mismatches in Package Names/Directory Structure

Windows uses a case-insensitive filesystem, but Kotlin and Java’s classpath resolution still cares about case consistency. Looking at your error:

\app\build\generated\source\kapt\stagingDebug...\DaggerAppComponent.java:49: error: cannot find symbol
import com...features.Main.splash_screen.SplashScreenActivity;

Notice the uppercase Main in the import path—chances are your actual Kotlin files are in a lowercase main directory (following Android’s lowercase package directory conventions). Even though Windows lets you access the folder with either case, the Java compiler (used under the hood by kapt) gets confused when the generated code’s import case doesn’t match the actual file’s package declaration.

  • Check your Kotlin file’s package declaration: Ensure SplashScreenActivity.kt starts with package com...features.main.splash_screen (lowercase main), not Main.
  • Verify directory structure: Make sure your project’s directory structure matches the package name exactly (e.g., src/main/java/com/.../features/main/splash_screen/).

2. Clean Up Gradle Build Caches

Windows’ Gradle cache sometimes gets corrupted with mixed-case path references, especially when switching between systems or updating dependencies. Run these commands in your project root to clear stale data:

# Clear project-specific build files
gradlew clean

# Clear global Gradle cache
gradlew cleanBuildCache

After cleaning, rebuild your project from scratch—this often fixes stale generated code referencing incorrect paths.

3. Remove Conflicting Kotlin Plugins

Your Gradle config includes both kotlin-platform-android and kotlin-android, which can cause build tool conflicts, especially with older Dagger versions:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-platform-android' // Unnecessary for non-multiplatform apps
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'

The kotlin-platform-android plugin is for Kotlin Multiplatform projects. If you’re not building a cross-platform app, remove it. Also, ensure your Kotlin version is compatible with Dagger 2.23.1 (Kotlin 1.3.x is recommended for this Dagger release).

4. Update Dagger to a More Recent Version

Dagger 2.23.1 is quite old (released in 2019), and newer versions have better compatibility with Kotlin and Windows’ filesystem quirks. Try updating to a stable modern version:

implementation "com.google.dagger:dagger:2.44.2"
implementation "com.google.dagger:dagger-android-support:2.44.2"
kapt "com.google.dagger:dagger-compiler:2.44.2"
kapt "com.google.dagger:dagger-android-processor:2.44.2"

Newer releases handle Kotlin metadata more reliably and include fixes for Windows-specific path resolution issues.

5. Tweak Kapt Configuration

Ensure kapt is properly configured to process Kotlin files before generating Dagger components. Add these lines to your build.gradle if they’re missing:

kapt {
    correctErrorTypes = true
}

This helps kapt generate more accurate code and reduces missing symbol errors.


If none of these steps work, you could try enabling case-sensitive filesystem emulation for your project folder (supported on Windows 10+), but that’s a more drastic measure. The first four fixes should resolve the issue in most cases.

内容的提问来源于stack exchange,提问作者Ashraf Atef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:27:15