升级至Android Studio Flamingo后Dagger项目编译失败求助
Fixes for Dagger Compilation Error After Android Studio Upgrade
1. Add JVM Export Flags to Compiler Args
In your app-level build.gradle file, add the following under the compileOptions block to grant access to the required internal JDK modules:
android { compileOptions { // Match source/target compatibility to your project's JDK version sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 compilerArgs.add('--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED') compilerArgs.add('--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED') } }
2. Verify JDK Consistency Across Machines
- Open Android Studio → File → Project Structure → SDK Location
- Confirm the JDK location matches the path used on the working machine.
- Ensure both machines run the same JDK version (e.g., OpenJDK 11 or Oracle JDK 11).
3. Enable Dagger's Aggregating Task
Add this to your app-level build.gradle to resolve annotation processing conflicts:
android { annotationProcessorOptions { arguments += [ "dagger.compiler.experimental.enableAggregatingTask": "true" ] } }
4. Clear Gradle Daemon Cache
Corrupted daemon cache can cause inconsistent behavior. Run these commands in your project root:
./gradlew clean ./gradlew --stop rm -rf ~/.gradle/caches # macOS/Linux # Windows: rmdir /s /q %USERPROFILE%\.gradle\caches
Then re-sync and rebuild the project.
5. Check Third-Party Plugin Compatibility
Ensure all custom/third-party Gradle plugins are updated to versions compatible with Gradle 7.4.2 and your Android Studio version. Temporarily disable non-essential plugins to rule out conflicts.
内容的提问来源于stack exchange,提问作者Pavel Poley
相关产品推荐
相关产品推荐

