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

Ability to upload AAB release build file #1050

Closed ArcherEmiya05 closed 2 years ago

ArcherEmiya05 commented 2 years ago

This command ./gradlew :app:publishReleaseBundle builds aab and release it to internal track. But what if we wanted to reuse the generated aab file for other purposes? Can we instead build aab file with gradle and provide it to GPP in the command to save build minute for CI CD? Thanks

SUPERCILEX commented 2 years ago

Yes: https://github.com/Triple-T/gradle-play-publisher#uploading-a-pre-existing-artifact

ArcherEmiya05 commented 2 years ago

Yes: https://github.com/Triple-T/gradle-play-publisher#uploading-a-pre-existing-artifact

Thanks a lot, one more question does ./gradlew :app:publishReleaseBundle command generates AAB file to the build folder? Cause we want to use that AAB that GPP task created for other task as well.

ArcherEmiya05 commented 2 years ago

We want to achieve something like this ./gradlew :app:publishReleaseBundle :app:uploadAabRelease. Where :app:publishReleaseBundle will generate release AAB file and publish it in internal track then :app:uploadAabRelease task reuses the cached results from this task and doesn't need run everything again.

SUPERCILEX commented 2 years ago

Publish just depends on the bundle task from AGP (don't remember what it's called). https://github.com/Triple-T/gradle-play-publisher/blob/4273731c8126cdbf071300882718ec2ae12f3e3c/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt#L464 You'll want to use the variant.artifacts.get(...) part.

ArcherEmiya05 commented 2 years ago

Thanks a lot!

ArcherEmiya05 commented 2 years ago

Publish just depends on the bundle task from AGP (don't remember what it's called).

https://github.com/Triple-T/gradle-play-publisher/blob/4273731c8126cdbf071300882718ec2ae12f3e3c/play/plugin/src/main/kotlin/com/github/triplet/gradle/play/PlayPublisherPlugin.kt#L464 You'll want to use the variant.artifacts.get(...) part.

I just want to follow up, does ./gradlew :app:publishReleaseBundle command uses :app:assembleRelease internally?

SUPERCILEX commented 2 years ago

No because that's a human task. There's an underlying task the AGP API gives us which does the actual building. If you want to use a named task, you can probably just depend on bundleRelease. (assembleRelease is for APKs)

ArcherEmiya05 commented 2 years ago

No because that's a human task. There's an underlying task the AGP API gives us which does the actual building. If you want to use a named task, you can probably just depend on bundleRelease. (assembleRelease is for APKs)

Is this the equivalent of ./gradlew :app:publishReleaseBundle in a more manual approach?

build.gradle

play {
    serviceAccountCredentials.set(file(PLAY_API_KEY_FILE))
    artifactDir.set(file("app/build/outputs/bundle/release"))
}

Gradle command ./gradlew clean :app:bundleRelease :app:publishBundle

Is the artifact dir here is enough or we should also explicitly add the file name app-release.aab in it?

SUPERCILEX commented 2 years ago

Oh, you need to run those in two separate builds or muck around with the task dependencies. If you use artifactDir, publishBundle will run immediately (without waiting for bundleRelease to finish).

ArcherEmiya05 commented 2 years ago

Oh, you need to run those in two separate builds or muck around with the task dependencies. If you use artifactDir, publishBundle will run immediately (without waiting for bundleRelease to finish).

You mean separate task?

./gradlew clean :app:bundleRelease // Keep the build artifacts for subsequent pipeline steps

./gradlew clean :app:publishBundle

SUPERCILEX commented 2 years ago

Don't run clean: ./gradlew :app:publishBundle

ArcherEmiya05 commented 2 years ago

Don't run clean: ./gradlew :app:publishBundle

My bad

ArcherEmiya05 commented 2 years ago

Hi, just want to raise this issue again. I actually tried this

First step

Build Bundle (Release)
...
./gradlew clean :app:bundleRelease"
          artifacts: # Keep these artifacts for subsequent pipeline steps
            - app/build/outputs/** # Artifacts are files that are produced by a step https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/

Second step


Deploy to PlayStore (Internal)
...
"./gradlew :app:publishBundle"

But it does not work, the task is successful but no bundle was uploaded to the store.

image

Artifacts from previous pipeline build was downloaded so I am pretty sure it not empty image

ArcherEmiya05 commented 2 years ago

Do I need to include the actual AAB file name in this path? artifactDir.set(file("app/build/outputs/bundle/release"))

Like this artifactDir.set(file("app/build/outputs/bundle/release/app-release.aab"))

SUPERCILEX commented 2 years ago

No, that shouldn't be necessary. I would add an ls -R step to see what files are present.

ArcherEmiya05 commented 2 years ago

No, that shouldn't be necessary. I would add an ls -R step to see what files are present.

Shouldn't we supposed to start at build folder like this? artifactDir.set(file("build/outputs/bundle/release")) since build.gradle is inside the app module already?

ArcherEmiya05 commented 2 years ago

I tried to download the artifact and its directory is this app\build\outputs\bundle\release

SUPERCILEX commented 2 years ago

Oh yeah, you're right. artifactDir.set(file("build/outputs/bundle/release")) should work.

ArcherEmiya05 commented 2 years ago

Oh yeah, you're right. artifactDir.set(file("build/outputs/bundle/release")) should work.

Thanks will try this

ArcherEmiya05 commented 2 years ago

No, that shouldn't be necessary. I would add an ls -R step to see what files are present.

Shouldn't we supposed to start at build folder like this? artifactDir.set(file("build/outputs/bundle/release")) since build.gradle is inside the app module already?

Solved, closing the issue now.