Skip to content

Improve Android Core Library Desugaring trait - #910

Merged
ktoso merged 2 commits into
swiftlang:mainfrom
madsodgaard:android-optional
Sep 4, 2026
Merged

Improve Android Core Library Desugaring trait#910
ktoso merged 2 commits into
swiftlang:mainfrom
madsodgaard:android-optional

Conversation

@madsodgaard

@madsodgaard madsodgaard commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

The previous work we had done for Android core library desugaring was purely a compile-time thing. However, it should really be a runtime thing. For example, if you have two apps:

  • App A: minSdk: 23
  • App B: minSdk: 24

On App A, java.util.Optional is desugared to j$.util.Optional
On App B, java.util.Optional is available

Previously, our trait would embed the desugared name into the binary That would mean if we enabled the trait to allow Optional use on API 23, then the same binary would fail on a project with minSdk: 24.

This PR refactors the trait to instead be a runtime "probe", that checks whether the desugared is available or not, and caches that for future use.

It also fixes a bug where we would not use the desugared name in JNIMethodCache, which would results in crashes for collections of optionals for example.

@madsodgaard
madsodgaard requested a review from ktoso as a code owner September 4, 2026 08:05
@madsodgaard madsodgaard changed the title Improve Android Core Library Desugaring Improve Android Core Library Desugaring trait Sep 4, 2026
@ktoso
ktoso merged commit e67104c into swiftlang:main Sep 4, 2026
41 of 42 checks passed
@ktoso ktoso mentioned this pull request Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants