Skip to content

Guard MSL altitude access with API level check for Android 13+ compat…#18

Merged
marcprux merged 1 commit into
skiptools:mainfrom
DaveKoz:main
Jun 4, 2026
Merged

Guard MSL altitude access with API level check for Android 13+ compat…#18
marcprux merged 1 commit into
skiptools:mainfrom
DaveKoz:main

Conversation

@DaveKoz
Copy link
Copy Markdown
Contributor

@DaveKoz DaveKoz commented Jun 4, 2026

…ibility

Thank you for contributing to the Skip project! Please use this space to describe your change and add any labels (bug, enhancement, documentation, etc.) to help categorize your contribution.

Please review the contribution guide at https://skip.dev/docs/contributing/ for advice and guidance on making high-quality PRs.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

@cla-bot cla-bot Bot added the cla-signed label Jun 4, 2026
@DaveKoz
Copy link
Copy Markdown
Contributor Author

DaveKoz commented Jun 4, 2026

Root cause
LocationProvider.swift:226 called location.hasMslAltitude(), which transpiles to the Android Location.hasMslAltitude() method. That method (and getMslAltitudeMeters()) was only added in API 33 (Android 13 / TIRAMISU). On older devices the JVM finds no such method and throws NoSuchMethodError, crashing in LocationEvent..

The change
I guarded the MSL altitude access behind a runtime SDK check so it's only invoked on Android 13+:

LocationProvider.swift:226-231
// hasMslAltitude()/getMslAltitudeMeters() were added in API 33 (Android 13); calling them on older devices throws NoSuchMethodError
if android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU, location.hasMslAltitude() {
self.altitude = location.getMslAltitudeMeters()
} else {
self.altitude = 0.0
}
On devices below API 33, altitude falls back to 0.0 (same fallback the original code used when MSL altitude was unset). The separate ellipsoidalAltitude field on the next line continues to populate from getAltitude(), which is available on all supported API levels.

This is the standard Skip pattern: the version constant resolves to android.os.Build.VERSION_CODES.TIRAMISU in the transpiled Kotlin, and the short-circuit && prevents hasMslAltitude() from ever being referenced on older runtimes.

No other hasMslAltitude/getMslAltitudeMeters usages exist in the source. The crash should be resolved on rebuild.

@marcprux marcprux merged commit 7ae4e4e into skiptools:main Jun 4, 2026
2 checks passed
@marcprux
Copy link
Copy Markdown
Member

marcprux commented Jun 4, 2026

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants