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.1k stars 340 forks source link

Exception with auto resolution when no conflict #879

Closed mattprecious closed 3 years ago

mattprecious commented 3 years ago

Describe the bug

We manually bumped the minor version of our app and now the publisher is throwing an IndexOutOfBoundsException when trying to resolve the version.

How To Reproduce

Manually change the version code to a non-conflicting version, and set:

resolutionStrategy = com.github.triplet.gradle.androidpublisher.ResolutionStrategy.AUTO

Versions

Tasks executed

publishInternalReleaseBundle

Expected behavior

No exception.

Additional context (if a crash, provide stack trace)

Caused by: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    at com.github.triplet.gradle.play.PlayPublisherPlugin$applyInternal$2$2$10.transform(PlayPublisherPlugin.kt:353)
    at com.github.triplet.gradle.play.PlayPublisherPlugin$applyInternal$2$2$10.transform(PlayPublisherPlugin.kt:59)

It seems like the version codes files is empty or non-existent.

SUPERCILEX commented 3 years ago

Oh shoot, I'm guessing this line is the culprit: https://github.com/Triple-T/gradle-play-publisher/blob/bcd707dbc793d115112cfbefe9aa895913559379/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/tasks/ProcessArtifactVersionCodes.kt#L51

I think you should be able to fix the crash by bringing the version code back to one: android { versionCode = 1 }. Does the fix the crash? If not, can you share what you changed in the build.gradle?

mattprecious commented 3 years ago

I manually published version 3280000 (3.28.0.0) to the store and ran our automated deploy job again and it successfully published 3280001.

SUPERCILEX commented 3 years ago

Ok, good to hear the crash is gone. I'll just have to fix that if statement.

mrbipbip commented 3 years ago

+1 here. I have the same issue at the same line (saw it in build-scan).

In my case, i'm using Gitlab to set my version code dynamically like below:

android {
    setVersionCode((System.getenv("CI_PIPELINE_IID") ?: "1").toInt())
    setVersionName("1.0.0")
    ...
}

Its works when i remove: resolutionStrategy.set(ResolutionStrategy.AUTO)

Note that:

onVariantProperties {
        for (output in outputs) {
            val processedVersionCode = output.versionCode.map { playVersionCode ->
                "${output.versionName}_$playVersionCode"
            }
            output.versionName.set(processedVersionCode)
        }
    }

Seems to write wrong info when uploaded to the Google Play Store (internal) 227 (property(java.lang.String, map(java.lang.String map(property(java.lang.Integer, fixed(class java.lang.Integer, 227))) check-type()))