Skip to content

Generated net.android.init.gradle.kts incompatible with Gradle 9.x (Kotlin type safety) #10737

@PureWeen

Description

@PureWeen

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["..."] returns String? (nullable)
  • Gradle 9.x's file() function requires Any (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

Metadata

Metadata

Labels

needs-triageIssues that need to be assigned.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions