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

Wrong authentication file is set in multiple flavours project #942

Closed mkubele closed 3 years ago

mkubele commented 3 years ago

Describe the bug

Hey, I have a project with multiple flavours and wrong authentication file is used when I specify authentication file for the exact flavour combination. Example of my configuration:

android {
   flavorDimensions("partner", "brand")
   productFlavors {
        register("special") {
            dimension = "partner"
        .....
        }
        register("default") {
            dimension = "partner"
        .....
        }

        register("first") {
            dimension = "brand"
        .....
        }

    buildTypes {
        getByName("debug") {
        .....
       }
        getByName("release") {
        .....
       }
   }

    play {
        releaseStatus.set(ReleaseStatus.DRAFT)
        enabled.set(false)
    }

    playConfigs {
        register("specialFirstRelease") {
            serviceAccountCredentials.set(SPECIAL_FIRST_KEY)
            enabled.set(true)
        }

        register("first") {
            serviceAccountCredentials.set(FIRST_KEY)
            enabled.set(true)
        }
    }
}

So when I run publishSpecialFirstReleaseBundle, _FIRSTKEY is used instead of the expected _SPECIAL_FIRSTKEY

How To Reproduce

Try to publish in a multi flavour project (as example above)

Versions

Tasks executed

publishSpecialFirstReleaseBundle

Expected behavior

Defined authentication file is used.

SUPERCILEX commented 3 years ago

Does this issue still occur with GPP 3.4.0? Can you also share the result of running ./gradlew help --debug | grep PlayExtensionConfig?

mkubele commented 3 years ago

Yes, the same occurs with the v3.4.0. This is the output of the help command:

2021-04-27T01:14:24.137+0200 [DEBUG] [org.gradle.api.Project] Extension computed for variant 'defaultFirstDebug': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.21.13828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:24.401+0200 [DEBUG] [org.gradle.api.Project] Extension computed for variant 'specialFirstDebug': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.21.13828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:24.540+0200 [DEBUG] [org.gradle.api.Project] Extension computed for variant 'defaultFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.21.13828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:24.706+0200 [DEBUG] [org.gradle.api.Project] Extension computed for variant 'specialFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/SPECIAL_FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=2.21.5828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:28.224+0200 [DEBUG] [org.gradle.api.Project] Extension resolved for variant 'defaultFirstDebug': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.21.13828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:28.224+0200 [DEBUG] [org.gradle.api.Project] Extension resolved for variant 'specialFirstDebug': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.21.13828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:28.225+0200 [DEBUG] [org.gradle.api.Project] Extension resolved for variant 'defaultFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.21.13828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-04-27T01:14:28.225+0200 [DEBUG] [org.gradle.api.Project] Extension resolved for variant 'specialFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/SPECIAL_FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=2.21.5828, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
SUPERCILEX commented 3 years ago

Hmmm, how do you know the wrong key is being used? The 4th line shows that SPECIAL_FIRST_KEY.json is used for specialFirstRelease.

mkubele commented 3 years ago

this is my guess by experiment. With this setting, I'm getting this error from the google api:

POST https://androidpublisher.googleapis.com/androidpublisher/v3/applications/APPLICATION/edits
             {
               "code": 403,
               "errors": [
                 {
                   "domain": "global",
                   "message": "The caller does not have permission",
                   "reason": "forbidden"
                 }
               ],
               "message": "The caller does not have permission",
               "status": "PERMISSION_DENIED"
             }

So after checking other settings I came to the conclusion it's caused by the used key. I tried to set the same key for both configurations and then it worked

    playConfigs {
        register("specialFirstRelease") {
            serviceAccountCredentials.set(SPECIAL_FIRST_KEY)
            enabled.set(true)
        }

        register("first") {
            serviceAccountCredentials.set(SPECIAL_FIRST_KEY)
            enabled.set(true)
        }
    }
SUPERCILEX commented 3 years ago

I'd lean more towards the key not actually having permissions. You can try this by specifying only FIRST_KEY... if it still doesn't have permissions then it's an issue with that key.

mkubele commented 3 years ago

Oh, I forgot to mention - it works fine with v2.8.0, that I used before and I upgraded from.

github-actions[bot] commented 3 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.

SUPERCILEX commented 3 years ago

Finally managed to repro!

SUPERCILEX commented 3 years ago

Once the build finishes can you check that the bug is fixed on your end? https://github.com/Triple-T/gradle-play-publisher#snapshot-builds

mkubele commented 3 years ago

I tried the 3.5.0-SNAPSHOT and it still does not work. I tried to run ./gradlew help --debug | grep PlayExtensionConfig and in the result I can see there is the wrong key set

2021-05-10T11:44:50.334+0200 [DEBUG] [org.gradle.api.Project] Extension computed for variant 'defaultFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.22.13806, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-05-10T11:44:50.386+0200 [DEBUG] [org.gradle.api.Project] Extension computed for variant 'specialFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.22.13806, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-05-10T11:44:53.510+0200 [DEBUG] [org.gradle.api.Project] Extension resolved for variant 'defaultFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.22.13806, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
2021-05-10T11:44:53.510+0200 [DEBUG] [org.gradle.api.Project] Extension resolved for variant 'specialFirstRelease': PlayExtensionConfig(enabled=true, serviceAccountCredentials=/Users/USER/.keys/FIRST_KEY.json, defaultToAppBundles=false, commit=true, fromTrack=null, track=internal, promoteTrack=null, userFraction=null, updatePriority=null, releaseStatus=DRAFT, releaseName=6.22.13806, resolutionStrategy=FAIL, retainArtifacts=[], retainMainObb=null, retainPatchObb=null)
SUPERCILEX commented 3 years ago

Did you change your playConfigs? The output of that command shouldn't have changed.

mkubele commented 3 years ago

No, the only thing I changed is the version. It seems something was messed up with Gradle. I still have the file from two weeks ago with the output and the key is set correctly there. But I double checked it now again, and the only version where the settings in the debug command output is correct is v2.8.0. All versions from v3.2.0 up are all set wrong now.

SUPERCILEX commented 3 years ago

Hmmm, can you maybe share more of your Gradle file? Something else must be messed up. Here's how I set up the test BTW: https://github.com/Triple-T/gradle-play-publisher/blob/ece2df894a31ff4425de446ecb4ebdbebb4c6361/play/plugin/src/test/kotlin/com/github/triplet/gradle/play/PlayPublisherPluginIntegrationTest.kt#L394-L416

mkubele commented 3 years ago

I realised that gradle file was actually changed - I switched from extension to the config you have in the test app. So, the correct file is set with v3.5.0-SNAPSHOT with this config:

this as ExtensionAware).extensions.configure<NamedDomainObjectContainer<PlayPublisherExtension>>("playConfigs") {
        register("specialFirstRelease") {
            serviceAccountCredentials.set(file(System.getProperty("user.home") + "/.keys/SPECIAL_FIRST_KEY"))
        }

        register("first") {
            serviceAccountCredentials.set(file(System.getProperty("user.home") + "/.keys/FIRST_KEY"))
        }
    }

The output of debug command is correct upload works flawlessly. Issue is when I use this way of config:


    play {
        track.set(getPlayPublishTrack())
        releaseStatus.set(if (track.equals("internal")) ReleaseStatus.COMPLETED else ReleaseStatus.DRAFT)
        enabled.set(false)
    }

    playConfigs {
        register("specialFirstRelease") {
            serviceAccountCredentials.set(file(System.getProperty("user.home") + "/.keys/SPECIAL_FIRST_KEY"))
            enabled.set(true)
        }

        register("first") {
            serviceAccountCredentials.set(file(System.getProperty("user.home") + "/.keys/FIRST_KEY"))
            enabled.set(true)
        }
    }
SUPERCILEX commented 3 years ago

(this as ExtensionAware).extensions.configure<NamedDomainObjectContainer<PlayPublisherExtension>>("playConfigs") and just playConfigs should be identical. (We have to use that ugly hack in the testapp because we can't use the plugins block.)

Maybe enabled is messing stuff up? Glad to hear the original bug is fixed though.

mkubele commented 3 years ago

Yes, it is fixed, thank you very much! Do you have any estimate of release date of the v3.5.0? Also, should I create a new issue regarding the config?

SUPERCILEX commented 3 years ago

No ETA on a new release, though I'd like to get one out soon (maybe this weekend or the next).

And sure, you can file an issue about the config. I'll probably need more details though because I can't repro.