We hit this while upgrading an Android project to both:
- Android Gradle Plugin
9.2.0 - SonarQube Gradle plugin
7.3.0.8198
The previous CI baseline, before this upgrade stack, used SonarQube Gradle plugin 7.2.3.7755 and completed successfully.
What worked before
Before this upgrade stack, the Sonar task completed successfully with:
- SonarQube Gradle plugin
7.2.3.7755 sonar.gradle.skipCompile=true- CI command:
./gradlew sonar -Dsonar.token=... -Pandroid.newDsl=false
That baseline still logged Java analyzer warnings about unresolved Android/JDK types, but they were non-fatal and the build ended with BUILD SUCCESSFUL.
What fails now
After upgrading to AGP 9.2.0 and SonarQube Gradle plugin 7.3.0.8198, the same CI command fails:
Execution failed for task ':sonar'.
> org.sonar.java.AnalysisException: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.
The project contains Java files in Android library modules, including:
- regular Java sources under
src/main/java/... - generated Java sources registered with
variant.sources.java?.addStaticSourceDirectory(...)
Possible root cause
From the scanner source, 7.3.0.8198 added a new AGP 9 code path in AndroidConfig.
That path appears to compute sonar.java.binaries using this hard-coded directory shape:
build/intermediates/javac/<componentName>/classes
For AGP 9.2.0, the actual JavaCompile output directory is:
build/intermediates/javac/<variant>/compile<Variant>JavaWithJavac/classes
For example:
build/intermediates/javac/debug/compileDebugJavaWithJavac/classes
Because the scanner later filters non-existing path properties before analysis, the guessed sonar.java.binaries path is removed. The scanner then sees Java source files but no valid sonar.java.binaries, which triggers the fatal Java analyzer error above.
Suggested direction
Instead of synthesizing the class output path from the component name, the AGP 9 path should use the matched JavaCompile task’s actual destinationDirectory, similar to the legacy AGP path that used variant.getJavaCompileProvider().getOrNull().getDestinationDirectory().
This avoids depending on AGP internal output directory layout and should be more robust for custom Gradle/AGP behavior.