Triple-T / gradle-play-publisher

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
MIT License
4.13k stars 341 forks source link

[AGP 4.2.0-alpha12]: AnalyticsEnabledApplicationVariantBuilder_Decorated cannot be cast to class ApplicationVariant #864

Closed chrisbanes closed 3 years ago

chrisbanes commented 4 years ago

Describe the bug

Plugin doesn't currently work with AGP 4.2.0-alpha12

Caused by: java.lang.ClassCastException: class com.android.build.api.component.analytics.AnalyticsEnabledApplicationVariantBuilder_Decorated cannot be cast to class com.android.build.api.variant.ApplicationVariant (com.android.build.api.component.analytics.AnalyticsEnabledApplicationVariantBuilder_Decorated and com.android.build.api.variant.ApplicationVariant are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6e5b0de3)
        at com.github.triplet.gradle.play.PlayPublisherPlugin$applyInternal$2.invoke(PlayPublisherPlugin.kt:59)
        at com.android.build.gradle.internal.dsl.CommonExtensionImpl$onVariants$1.execute(CommonExtensionImpl.kt:230)
        at com.android.build.gradle.internal.dsl.CommonExtensionImpl$onVariants$1.execute(CommonExtensionImpl.kt:40)
        at com.android.build.api.variant.impl.VariantOperations.executeActions(VariantOperations.kt:61)
        at com.android.build.gradle.internal.dsl.CommonExtensionImpl.executeVariantOperations(CommonExtensionImpl.kt:242)
        at com.android.build.gradle.internal.dsl.BaseAppModuleExtension.executeVariantOperations(BaseAppModuleExtension.kt)
        at com.android.build.gradle.internal.dsl.BaseAppModuleExtension.executeVariantOperations(BaseAppModuleExtension.kt:37)
        at com.android.build.gradle.internal.VariantManager.createVariant(VariantManager.java:370)
        at com.android.build.gradle.internal.VariantManager.createVariantsFromCombination(VariantManager.java:847)
        at com.android.build.gradle.internal.VariantManager.computeVariants(VariantManager.java:270)
        at com.android.build.gradle.internal.VariantManager.createVariants(VariantManager.java:215)
        at com.android.build.gradle.internal.plugins.BasePlugin.createAndroidTasks(BasePlugin.java:654)
        at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:69)
        ... 159 more

Versions

SUPERCILEX commented 4 years ago

Sigh, keeping up with AGP is exhausting. I tried to upgrade, but couldn't figure out how to get debuggability info. Might try again this week, but probs not worth it since the next alpha is likely going to break something else anyway.

b95505017 commented 4 years ago

Maybe it would be great to support publish to GP officially by AGP

SUPERCILEX commented 4 years ago

A possibility, but not likely. Plugin authors just need a stable public API and everything would be fine... but here we are. :man_shrugging:

chrisbanes commented 4 years ago

Thanks for doing this @SUPERCILEX, very appreciated!

wojtek-kalicinski commented 4 years ago

@SUPERCILEX apologies for the problems you're having. These kinds of breakages are exactly why the AGP team are working on a stable API right now. And even though they are doing everything they can to maintain binary and source compatibility with previous plugins, it's not always possible and unfortunately some of the new APIs that have been added in 4.1/4.2 canaries are still incubating, which means they have and will change while they iterate on them.

For instance, onVariant/onVariantProperties (and maybe some of the underlying types) are being rewritten right now, so... sorry about that, but it's for the best. We're aiming to have these stable in 4.2+1 version, whatever it will be (4.3, 5.0, who knows).

If I find some time I'll take a look at the issue you're seeing, but I don't currently have a checkout of your project handy, so it might take me a while until I get to it.

SUPERCILEX commented 4 years ago

@wojtek-kalicinski I really do love the new APIs, so I'm sure it'll work out in the end. :) I guess my main concern is that these things will stay incubating forever -- reaching API stability in 4.3/5.0 would be awesome.

prawen commented 4 years ago

Hello,

I'm facing the same issue. May I know which version is working fine at this moment ? I need to publish apps. Gradle Play Publisher: ? Gradle Wrapper: ? Android Gradle Plugin: ?

I have tried upgrading, downgrading. But nothing is working. Is it broken for all releases ?

peterfortuin commented 4 years ago

I run into the same problem today but still wanted to publish my app to the Play Store. Because I wanted to use Jetpack Compose I upgraded the Android Gradle Plugin to 4.2.0-alpha13. To work around this problem I downgraded to AGP 4.1.0-rc03. Work also with Jetpack Compose and with GPP 3.0.0.

Working combination: Gradle Play Publisher: 3.0.0 Gradle Wrapper: 6.6.1 Android Gradle Plugin: 4.1.0-rc03 Jetpack Compose: 1.0.0-alpha03

I hope this helps until the issue gets resolved.

wojtek-kalicinski commented 4 years ago

@SUPERCILEX I haven't had time to look into the issue yet unfortunately, but I suspect the problem might be because two classes were renamed in one of recent the AGP releases: Variant became VariantBuilder VariantProperties became Variant

SUPERCILEX commented 4 years ago

Made a bit of progress. The real issue is that you can no longer access VariantBuilder and Variant at the same time. This doesn't work anymore:

android.onVariantProperties {
  onProperties { ... }
}

So I have to resort to hacks again that will inevitably break: https://github.com/Triple-T/gradle-play-publisher/commit/048191a19c3739d3d5c22802b40aa7b120721f9f#diff-ef31e97b4dbf7e13d2c288d8464199a3.

Currently I'm stuck because I can't figure out a way to order output.versionCode.set(...) overrides. Something was changed and now the plugin gets run first which means anybody trying to initialize version codes themselves first will break the auto version code resolution. The failing test in question is here: https://github.com/Triple-T/gradle-play-publisher/blob/354812b6d789abee4d2c22c598424f73962b54c5/play/plugin/src/test/kotlin/com/github/triplet/gradle/play/tasks/ProcessArtifactVersionCodesIntegrationTest.kt#L59-L92

ChristianKatzmann commented 4 years ago

@SUPERCILEX Hey Alex, have you made any progress on this? @wojtek-kalicinski Can you assist somehow?

SUPERCILEX commented 4 years ago

Nah, still haven't figured out the ordering. That said, I'd like to unblock people so I released an unofficial 3.2.0 snapshot. It's compatible with alpha12 and alpha13.

chrisbanes commented 4 years ago

Just confirming, 3.2.0-SNAPSHOT works for me. Thanks Alex! 🙌

peterfortuin commented 4 years ago

3.2.0-SNAPSHOT also works for me. I'm on AGP 4.2.0-alpha14.

hardysim commented 3 years ago

I've just updated to the new Android Studio beta (4.2.0-beta01) and ran into the same issue. For me, both are working: 3.2.0-SNAPSHOT and 3.1.0-SNAPSHOT.

Am I'm right that those versions are "compiling" but not "working"? What is not working? Or why is this issue still open and no new official release available?

SUPERCILEX commented 3 years ago

Auto resolution with apk splits is broken, but I'm guessing close to no one is using that.

SUPERCILEX commented 3 years ago

See #892

I'll have time to get all this going in a few weeks.

SUPERCILEX commented 3 years ago

https://github.com/Triple-T/gradle-play-publisher/releases/tag/3.1.0-agp4.2