-
Notifications
You must be signed in to change notification settings - Fork 565
Open
Labels
needs-triageIssues that need to be assigned.Issues that need to be assigned.
Description
Summary
Microsoft.Android.Sdk generates Kotlin DSL scripts (net.android.init.gradle.kts) that are incompatible with Gradle 9.x due to stricter Kotlin type checking.
Error
When building a .NET Android project with Gradle 9.x, the following error occurs:
e: file:///.../obj/Debug/net10.0-android/gradle/net.android.init.gradle.kts:11:36:
Argument type mismatch: actual type is 'String?', but 'Any' was expected.
FAILURE: Build failed with an exception.
* Where:
Initialization script '.../obj/Debug/net10.0-android/gradle/net.android.init.gradle.kts' line: 11
* What went wrong:
Script compilation error:
Line 11: layout.buildDirectory.set(file(gradle.startParameter.projectProperties["netAndroidBuildDirOverride"]))
^ Argument type mismatch: actual type is 'String?', but 'Any' was expected.
Root Cause
The generated code in net.android.init.gradle.kts line 11:
layout.buildDirectory.set(file(gradle.startParameter.projectProperties["netAndroidBuildDirOverride"]))gradle.startParameter.projectProperties["..."]returnsString?(nullable)- Gradle 9.x's
file()function requiresAny(non-nullable) - Gradle 9.x has stricter Kotlin type checking and rejects the nullable type
Suggested Fix
Handle the nullable case in the generated Kotlin script:
gradle.startParameter.projectProperties["netAndroidBuildDirOverride"]?.let {
layout.buildDirectory.set(file(it))
}Environment
- Microsoft.Android.Sdk.Darwin: 36.0.0-preview.7.229
- Gradle: 9.0.0
- Target Framework: net10.0-android
Impact
This blocks .NET Android/MAUI projects from upgrading to Gradle 9.x and AGP 9.x.
Related
- Fix Android build failure by explicitly specifying build-tools 36.0.0 maui#33727 - Fix Android build failure by explicitly specifying build-tools 36.0.0
Copilot
Metadata
Metadata
Assignees
Labels
needs-triageIssues that need to be assigned.Issues that need to be assigned.