Skip to content

Too easy to get mixed SDK versions when using with Android Gradle plugin #450

@boringcactus

Description

@boringcactus

Platform

Apple, Android

Installed

CocoaPods

Version

0.18.0

Steps to Reproduce

  1. Install latest version of sentry-kmp Gradle plugin (0.18.0, uses Java SDK 8.17.0) and latest version of sentry-android Gradle plugin (5.9.0, defaults to Java SDK 8.19.0)

Expected Result

Android app does not crash on Sentry init.

Actual Result

Android app crashes on Sentry init due to mixed SDK versions 8.17.0 and 8.19.0.

Hardcoding autoInstallation { sentryVersion = "8.17.0" } in the sentry-android config works, until sentry-kmp upgrades its Sentry Java SDK version again, and now that needs to be manually synchronized on every sentry-kmp update, and there’s not even a straightforward way to test for it.

There has to be a better way. I tried like a dozen different Gradle mechanisms to override the sentry-kmp Java SDK version, including some with the sentry-java BOM, but none of them worked. Dynamically retrieving sentry-kmp’s Java SDK version wound up working, but only with far too much Gradle wrestling.

far too much Gradle wrestling
autoInstallation {
    sentryVersion = provider {
        val bareKMPConfig = configurations.detachedConfiguration(libs.sentry.kmp.get())
        val resolvedDependencies = bareKMPConfig.incoming.resolutionResult
        val resolvedModuleVersions =
            resolvedDependencies.allComponents.mapNotNull { it.moduleVersion }
        val transitiveSentryCore =
            resolvedModuleVersions.find { it.module.toString() == "io.sentry:sentry" }
        checkNotNull(transitiveSentryCore) {
                "Could not find io.sentry:sentry among ${resolvedModuleVersions.joinToString(prefix = "[", postfix = "]")}"
            }
            .version
    }
}

I would love to be able to delete that. If there was a way to make sentry-android automatically use the same Java SDK version as sentry-kmp with zero configuration, that’d be the ideal fix; if there was a well-documented manual config step to get that behavior, that’d be close enough; if there was at least a way to check at build time for mixed SDK versions, that’d still be an improvement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions