Skip to content

Commit e553923

Browse files
committed
AAB Publisher - support specifying existing bundle directory instead of building AAB on the fly.
1 parent 45918bd commit e553923

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

.github/workflows/android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ jobs:
261261
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
262262

263263
- name: Publish release App Bundle to Play Store
264-
run: ./gradlew publishBundleToGooglePlay
264+
run: ./gradlew publishBundleToGooglePlay -PartifactDir android/app/build/outputs/bundle/prodRelease
265265

266266
- name: Cleanup secrets
267267
if: always()

build-logic/aab-publisher/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ To publish the bundle to Google Play:
2828
```
2929

3030
The task will upload the Android App Bundle (AAB) file for the configured build variant to Google Play's Internal Testing track.
31+
32+
To specify a pre-existing bundle directory instead of building the AAB on the fly:
33+
34+
```bash
35+
./gradlew publishBundleToGooglePlay -PartifactDir=path/to/bundle/directory
36+
```

build-logic/aab-publisher/src/main/kotlin/io/github/reactivecircus/aabpublisher/AabPublisherGradlePlugin.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ public class AabPublisherGradlePlugin : Plugin<Project> {
1414
extensions.configure(ApplicationAndroidComponentsExtension::class.java) { extension ->
1515
extension.onVariants { variant ->
1616
if (!variant.name.equals(aabPublisherExtension.variant.get(), ignoreCase = true)) return@onVariants
17+
val artifactDirPath = providers.gradleProperty("artifactDir")
1718
tasks.register(
1819
"publishBundleToGooglePlay",
1920
PublishBundleToGooglePlay::class.java,
2021
) {
2122
it.group = "AAB Publisher"
2223
it.description = getTaskDescription(variant.name)
23-
it.bundle.set(variant.artifacts.get(SingleArtifact.BUNDLE))
24+
if (artifactDirPath.isPresent) {
25+
it.artifactDir.set(rootProject.layout.projectDirectory.dir(artifactDirPath))
26+
} else {
27+
it.bundle.set(variant.artifacts.get(SingleArtifact.BUNDLE))
28+
}
2429
it.serviceAccountCredentials.set(aabPublisherExtension.serviceAccountCredentials)
2530
it.applicationId.set(variant.applicationId)
2631
}

build-logic/aab-publisher/src/main/kotlin/io/github/reactivecircus/aabpublisher/PublishBundleToGooglePlay.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,31 @@ import com.github.triplet.gradle.androidpublisher.PlayPublisher
77
import com.github.triplet.gradle.androidpublisher.ReleaseStatus
88
import com.github.triplet.gradle.androidpublisher.ResolutionStrategy
99
import org.gradle.api.DefaultTask
10+
import org.gradle.api.file.DirectoryProperty
1011
import org.gradle.api.file.RegularFileProperty
1112
import org.gradle.api.provider.Property
1213
import org.gradle.api.tasks.Input
1314
import org.gradle.api.tasks.InputFile
15+
import org.gradle.api.tasks.Internal
16+
import org.gradle.api.tasks.Optional
1417
import org.gradle.api.tasks.PathSensitive
1518
import org.gradle.api.tasks.PathSensitivity
1619
import org.gradle.api.tasks.TaskAction
1720
import org.gradle.work.DisableCachingByDefault
1821
import org.gradle.work.NormalizeLineEndings
22+
import java.io.File
1923

2024
@DisableCachingByDefault
2125
internal abstract class PublishBundleToGooglePlay : DefaultTask() {
26+
@get:Optional
2227
@get:InputFile
2328
@get:PathSensitive(PathSensitivity.RELATIVE)
2429
@get:NormalizeLineEndings
2530
abstract val bundle: RegularFileProperty
2631

32+
@get:Internal
33+
abstract val artifactDir: DirectoryProperty
34+
2735
@get:InputFile
2836
@get:PathSensitive(PathSensitivity.RELATIVE)
2937
@get:NormalizeLineEndings
@@ -34,7 +42,7 @@ internal abstract class PublishBundleToGooglePlay : DefaultTask() {
3442

3543
@TaskAction
3644
fun execute() {
37-
val bundleFile = bundle.asFile.get()
45+
val bundleFile = findBundleFile()
3846
val credentialsFile = serviceAccountCredentials.asFile.get()
3947
val appId = applicationId.get()
4048

@@ -89,4 +97,21 @@ internal abstract class PublishBundleToGooglePlay : DefaultTask() {
8997
}
9098
}
9199
}
100+
101+
private fun findBundleFile(): File = if (artifactDir.isPresent) {
102+
val dir = artifactDir.get().asFile
103+
require(dir.exists() && dir.isDirectory) {
104+
"Artifact directory does not exist or is not a directory: $dir"
105+
}
106+
val aabFiles = dir.listFiles { file -> file.extension == "aab" } ?: emptyArray()
107+
require(aabFiles.isNotEmpty()) {
108+
"No AAB file found in artifact directory: $dir"
109+
}
110+
require(aabFiles.size == 1) {
111+
"Multiple AAB files found in artifact directory: $dir. Expected exactly one."
112+
}
113+
aabFiles.first()
114+
} else {
115+
bundle.asFile.get()
116+
}
92117
}

build-logic/v2p/src/main/kotlin/io/github/reactivecircus/v2p/V2PExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public interface V2PCodegenOptions {
3939
@get:Input
4040
public val generateAsListFunction: Property<Boolean>
4141

42-
@get:Input
4342
@get:Optional
43+
@get:Input
4444
public val subpackage: Property<String>
4545
}
4646

0 commit comments

Comments
 (0)