bugsnag / bugsnag-android-gradle-plugin

Gradle plugin for BugSnag which uploads ProGuard, DexGuard and NDK mapping files, and sends build notifications
https://docs.bugsnag.com/build-integrations/gradle/
MIT License
70 stars 38 forks source link

Access version code lazily via provider #416

Closed jrodbx closed 3 years ago

jrodbx commented 3 years ago

Closes #384.

Goal

To unblock consumers (such as Square/CashApp) to use the Bugsnag Android plugin with AGP 7.0 final.

Design

The inevitable fix would be to switch from using the now-legacy variant api:

            val android = project.extensions.getByType(AppExtension::class.java)
            android.applicationVariants.configureEach { variant ->

to the new provider api, a la:

            val android = project.extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
            android.onVariants { variant -> 
                variant.outputs.map { output -> output.versionCode }
            }

but that would have been a more substantial change.

Changeset

Wrapping output.versionCode in a Callable which can be passed to a DefaultProvider for lazy initialization.

Testing

I pushed to our internal Artifactory instance and ran the following command successfully:

./gradlew publishInternalReleaseBundle --dry-run

as outlined in https://github.com/Triple-T/gradle-play-publisher/issues/940#issue-862925799

cc: @egorand @SUPERCILEX

yousif-bugsnag commented 3 years ago

Hey @jrodbx, thanks for the PR! We'll look to review this as soon as priorities allow.

lemnik commented 3 years ago

Hi @jrodbx / @ZacSweers.

Thanks for this PR and your input. I hope you don't mind that we took this as inspiration for the logic here: https://github.com/bugsnag/bugsnag-android-gradle-plugin/pull/427/files#diff-0b3ba5e394543c53bbd77a52b87f07c4ff12e47518f2f3b26f1cd28f8246d7fcR218

This allows us to cover the entire Manifest merge including versionCode and versionName overrides in variants, along with handling our own meta-data overrides that can appear in AndroidManifest. I believe the change solves the problems you were having, and was released as part of v7.1.0.

Please let us know if this is still an issue - and thanks again.