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

resolutionStrategy = "ignore" does not ignore 403 ("APK specifies a version code that has already been used.") #679

Closed y-a-n-n closed 5 years ago

y-a-n-n commented 5 years ago

Describe the bug

I have an application with several product flavors which are effectively re-skins of the same application with changed themes and configuration. The flavors are defined in my build.gradle as below:

flavorDimensions "brand"
    productFlavors {
        myApp{
            dimension "brand"
        }
        brandOne{
            applicationId "com.myApp.brandOne"
            dimension "brand"
        }
        brandTwo{
            applicationId "com.myApp.brandTwo"
            dimension "brand"
        }

All in all, there are more than 20 flavors including the generic/main app. All of these need to be built and released when core code changes.

How To Reproduce

My release process involves:

./gradlew clean
./gradlew testMyAppReleaseUnitTest
./gradlew publishApk

The process runs nicely for while, then eventually dies on the 403 shown below, for the same flavor each time. By this point, some of the flavors have been successfully updated, including the one that has allegedly failed.

Interestingly, the failed apk always seems to correspond to my "main" generic app rather than any of the other variants.

It seems the plugin is trying to upload the same flavor twice, and stopping the whole build when it fails even though I have resolutionStrategy = "ignore" in my config. I then can't run again, because it fails as soon as it gets to a flavor that was successfully uploaded on the previous run.

My issues: **1. Why do I get the first 403 error? I have never uploaded an apk with this version number before to any track

  1. Why isn't resolutionStrategy = "ignore" allowing the build to continue with other variants?**

Versions

\--- com.github.triplet.gradle:play-publisher:2.3.0-SNAPSHOT

Gradle 5.4.1

+--- com.android.tools.build:gradle:3.5.0-beta05

Tasks executed

./gradlew clean
./gradlew testMyAppReleaseUnitTest
./gradlew publishApk

Expected behavior

The plugin builds and uploads all variants successfully to the Alpha track. In case of re-running after a previous interruption, failed variants do not stop the whole task, allowing other variants to be uploaded.

Additional context (if a crash, provide stack trace)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myApp:publishmyAppReleaseApk'.
> A failure occurred while executing com.github.triplet.gradle.play.tasks.PublishApk$ApksUploader
   > There was a failure while executing work items
      > A failure occurred while executing com.github.triplet.gradle.play.tasks.PublishApk$ApksUploader$Uploader
         > 403 Forbidden
           {
             "code" : 403,
             "errors" : [ {
               "domain" : "androidpublisher",
               "message" : "APK specifies a version code that has already been used.",
               "reason" : "apkNotificationMessageKeyUpgradeVersionConflict"
             } ],
             "message" : "APK specifies a version code that has already been used."
           }

plugin config in build.gradle:

play {
    serviceAccountCredentials = file(System.getenv("RELEASE_KEY"))
    track = "alpha"
    resolutionStrategy = "ignore"
}
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

y-a-n-n commented 5 years ago

Would prefer that this issue remain open as it is still occurring.

SUPERCILEX commented 5 years ago

Sorry about that, I haven't had time to investigate.

y-a-n-n commented 5 years ago

No problem, just didn't want it to get closed automatically.

y-a-n-n commented 5 years ago

Additional context: I suspect this may(?) have something to do with per-variant uploads/tasks occurring in some concurrent fashion. After I manually upload the missed artifacts to the Alpha track for each respective variant, I see a similar issue when trying to promote them all to production:

gradlew promoteArtifact --from-track alpha --track production

This promotes several variants successfully, but not all of them and eventually dies on the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myApp:promotePlayConfigsReleaseArtifact'.
> A failure occurred while executing com.github.triplet.gradle.play.tasks.PromoteRelease$Promoter
   > 410 Gone
     {
       "code" : 410,
       "errors" : [ {
         "domain" : "androidpublisher",
         "message" : "This Edit has been deleted.",
         "reason" : "editDeleted"
       } ],
       "message" : "This Edit has been deleted."
     }

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

A similar issue raised in another automated deployment library suggests that concurrent execution is the problem:

Failed to upload apk, error: googleapi: Error 410: This Edit has been deleted., editDeleted

...but these issues seem to occur for me even when run manually on my local machine, ruling out CI misconfiguration as far as I can tell

y-a-n-n commented 5 years ago

Closing as this appears to have been fixed by updating to version 2.5.0