diff --git a/buildSrc/src/main/kotlin/custom/Auth.kt b/buildSrc/src/main/kotlin/custom/Auth.kt index 0a1b62d9f..df3908847 100644 --- a/buildSrc/src/main/kotlin/custom/Auth.kt +++ b/buildSrc/src/main/kotlin/custom/Auth.kt @@ -16,6 +16,8 @@ package custom +import com.android.build.api.variant.VariantOutput +import com.android.build.gradle.api.ApkVariantOutput import com.google.api.client.googleapis.auth.oauth2.GoogleCredential import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport import com.google.api.client.http.FileContent @@ -79,29 +81,29 @@ class Transaction( FileContent("application/octet-stream", file) ).execute().prettyPrint() - fun attachExpansionTo(versionCode: Int): ExpansionFile = + fun attachExpansionTo(expansionCode: Int, apkVariantOutput: ApkVariantOutput): ExpansionFile = publisher.edits().expansionfiles().update( packageName, editId, - versionCode, + apkVariantOutput.versionCodeOverride, "main", - ExpansionFile().apply { referencesVersion = versionCode } + ExpansionFile().apply { referencesVersion = expansionCode } ).execute().prettyPrint() - fun uploadBundle(outputFile: File) { - publisher.edits().bundles().upload( + fun uploadApk(apkVariantOutput: ApkVariantOutput) { + publisher.edits().apks().upload( packageName, editId, - FileContent("application/octet-stream", outputFile) + FileContent("application/octet-stream", apkVariantOutput.outputFile) ).execute().prettyPrint() } - fun addToTrackInDraft(versionCode: Int, versionName: String?): Track = + fun addToTrackInDraft(apkVariants: List): Track = publisher.edits().tracks().update(packageName, editId, "alpha", Track().apply { releases = listOf(TrackRelease().apply { status = "draft" - name = versionName - versionCodes = listOf(versionCode.toLong()) + name = apkVariants[0].versionNameOverride + versionCodes = apkVariants.map { it.versionCodeOverride.toLong() } }) track = "alpha" }).execute().prettyPrint() diff --git a/custom/build.gradle.kts b/custom/build.gradle.kts index 986c81061..f79ea04bd 100644 --- a/custom/build.gradle.kts +++ b/custom/build.gradle.kts @@ -1,11 +1,10 @@ -import com.android.build.gradle.api.ApplicationVariant import com.android.build.gradle.api.ApkVariantOutput +import com.android.build.gradle.api.ApplicationVariant import com.android.build.gradle.internal.dsl.ProductFlavor import custom.CustomApps import custom.createPublisher import custom.transactionWithCommit import plugin.KiwixConfigurationPlugin -import java.io.FileNotFoundException import java.net.URI import java.net.URL @@ -26,16 +25,13 @@ android { all { File("$projectDir/src", "$name/$name.zim").let { createDownloadTask(it) - createPublishBundleWithExpansionTask(it, applicationVariants) + createPublishApkWithExpansionTask(it, applicationVariants) } } } - - bundle { - language { - // This is disabled so that the App Bundle does NOT split the APK for each language. - // We're gonna use the same APK for all languages. - enableSplit = false + splits { + abi { + isUniversalApk = false } } } @@ -65,12 +61,12 @@ fun ProductFlavor.fetchUrl(): String { } } -fun ProductFlavor.createPublishBundleWithExpansionTask( +fun ProductFlavor.createPublishApkWithExpansionTask( file: File, applicationVariants: DomainObjectSet ): Task { val capitalizedName = name.capitalize() - return tasks.create("publish${capitalizedName}ReleaseBundleWithExpansionFile") { + return tasks.create("publish${capitalizedName}ReleaseApkWithExpansionFile") { group = "publishing" description = "Uploads $capitalizedName to the Play Console with an Expansion file" doLast { @@ -79,20 +75,11 @@ fun ProductFlavor.createPublishBundleWithExpansionTask( createPublisher(File(rootDir, "playstore.json")) .transactionWithCommit(packageName) { val variants = - applicationVariants.releaseVariantsFor(this@createPublishBundleWithExpansionTask) - val generatedBundleFile = - File( - "$buildDir/outputs/bundle/${capitalizedName.toLowerCase()}" + - "Release/custom-${capitalizedName.toLowerCase()}-release.aab" - ) - if (generatedBundleFile.exists()) { - uploadBundle(generatedBundleFile) - uploadExpansionTo(file, variants[0].versionCode) - attachExpansionTo(variants[0].versionCode) - addToTrackInDraft(variants[0].versionCode, versionName) - } else { - throw FileNotFoundException("Unable to find generated aab file") - } + applicationVariants.releaseVariantsFor(this@createPublishApkWithExpansionTask) + variants.forEach(::uploadApk) + uploadExpansionTo(file, variants[0].versionCodeOverride) + variants.drop(1).forEach { attachExpansionTo(variants[0].versionCodeOverride, it) } + addToTrackInDraft(variants) } } } @@ -100,14 +87,13 @@ fun ProductFlavor.createPublishBundleWithExpansionTask( fun DomainObjectSet.releaseVariantsFor(productFlavor: ProductFlavor) = find { it.name.equals("${productFlavor.name}Release", true) }!! - .outputs.filterIsInstance() - .filter { it.baseName.contains("universal") }.sortedBy { it.versionCode } + .outputs.filterIsInstance().sortedBy { it.versionCodeOverride } afterEvaluate { - tasks.filter { it.name.contains("ReleaseBundleWithExpansionFile") }.forEach { + tasks.filter { it.name.contains("ReleaseApkWithExpansionFile") }.forEach { val flavorName = - it.name.substringAfter("publish").substringBefore("ReleaseBundleWithExpansionFile") + it.name.substringAfter("publish").substringBefore("ReleaseApkWithExpansionFile") it.dependsOn.add(tasks.getByName("download${flavorName}Zim")) - it.dependsOn.add(tasks.getByName("bundle${flavorName}Release")) + it.dependsOn.add(tasks.getByName("assemble${flavorName}Release")) } }