Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: enable split APKs for F-Droid builds
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Jan 4, 2024
1 parent 5f27c04 commit 6d20a72
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
5 changes: 5 additions & 0 deletions build-logic/ide/src/main/java/FDroidConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ object FDroidConfig {
private set
get() = hasRead && field

var fDroidBuildArch: String? = null
private set

var fDroidVersionName: String? = null
private set

Expand All @@ -40,6 +43,7 @@ object FDroidConfig {
private set

const val PROP_FDROID_BUILD = "ide.build.fdroid"
const val PROP_FDROID_BUILD_ARCH = "ide.build.fdroid.arch"
const val PROP_FDROID_BUILD_VERSION = "ide.build.fdroid.version"
const val PROP_FDROID_BUILD_VERCODE = "ide.build.fdroid.vercode"
const val PROP_FDROID_AAPT2FILE_ARM64 = "ide.build.fdroid.aapt2File.arm64-v8a"
Expand All @@ -63,6 +67,7 @@ object FDroidConfig {
hasRead = true
isFDroidBuild = properties.getProperty(PROP_FDROID_BUILD, null).toBoolean()

fDroidBuildArch = properties.getProperty(PROP_FDROID_BUILD_ARCH, null)
fDroidVersionName = properties.getProperty(PROP_FDROID_BUILD_VERSION, null)
fDroidVersionCode = properties.getProperty(PROP_FDROID_BUILD_VERCODE, null)?.toInt()

Expand Down
6 changes: 1 addition & 5 deletions build-logic/ide/src/main/java/ProjectConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ val Project.projectVersionCode: Int
?: throw IllegalStateException(
"Cannot extract version code. Invalid version string '$version'. Version names must be SEMVER with 'v' prefix")

// When split APKs are enabled, version codes will be handled by AndroidModuleConf
// For universal APKs, the version code will be the verisonCode * 100 + incr e.g. 270 * 100 + 1 = 27001
// If split APKs are disabled, then this version code operation will be applied by default
// this is because the APK that will be produced in this case will effectively be a universal APK
return versionCode * (if (areSplitApksEnabled) 1 else 100)
return versionCode
}

val Project.publishingVersion: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.itsaky.androidide.plugins.conf

import BuildConfig
import areSplitApksEnabled
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.variant.FilterConfiguration
Expand Down Expand Up @@ -89,26 +88,25 @@ fun Project.configureAndroidModule(
"\"${abi}\"")
}

if (project.areSplitApksEnabled) {
splits {
abi {
reset()
isEnable = true
isUniversalApk = true
include(*flavorsAbis.keys.toTypedArray())
}
splits {
abi {
reset()
isEnable = true
isUniversalApk = false
include(*flavorsAbis.keys.toTypedArray())
}
}

extensions.getByType(ApplicationAndroidComponentsExtension::class.java).apply {
onVariants { variant ->
variant.outputs.forEach { output ->
extensions.getByType(ApplicationAndroidComponentsExtension::class.java).apply {
onVariants { variant ->
variant.outputs.forEach { output ->

// version code increment
val verCodeIncr = flavorsAbis[output.getFilter(
FilterConfiguration.FilterType.ABI)?.identifier] ?: 0
// version code increment
val verCodeIncr = flavorsAbis[output.getFilter(
FilterConfiguration.FilterType.ABI)?.identifier]
?: throw UnsupportedOperationException("Universal APKs are not supported!")

output.versionCode.set(100 * projectVersionCode + verCodeIncr)
}
output.versionCode.set(100 * projectVersionCode + verCodeIncr)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,35 @@ abstract class SetupAapt2Task : DefaultTask() {
@TaskAction
fun setupAapt2() {

AAPT2_CHECKSUMS.forEach { (arch, checksum) ->
// When building for F-Droid, simply copy the aapt2 file
if (project.isFDroidBuild) {
val arch = FDroidConfig.fDroidBuildArch!!

val file = outputDirectory.file("${arch}/libaapt2.so").get().asFile
file.parentFile.deleteRecursively()
file.parentFile.mkdirs()

if (project.isFDroidBuild) {
val aapt2File = requireNotNull(FDroidConfig.aapt2Files[arch]) {
"F-Droid build is enabled but path to AAPT2 file for $arch is not set."
}

val aapt2 = File(aapt2File)
val aapt2File = requireNotNull(FDroidConfig.aapt2Files[arch]) {
"F-Droid build is enabled but path to AAPT2 file for $arch is not set."
}

require(aapt2.exists() && aapt2.isFile) {
"F-Droid AAPT2 file does not exist or is not a file: $aapt2"
}
val aapt2 = File(aapt2File)

logger.info("Copying $aapt2 to $file")
aapt2.copyTo(file, overwrite = true)
return
require(aapt2.exists() && aapt2.isFile) {
"F-Droid AAPT2 file does not exist or is not a file: $aapt2"
}

logger.info("Copying $aapt2 to $file")
aapt2.copyTo(file, overwrite = true)
return
}

// When not building for F-Droid, download aapt2 files from GitHub
AAPT2_CHECKSUMS.forEach { (arch, checksum) ->
val file = outputDirectory.file("${arch}/libaapt2.so").get().asFile
file.parentFile.deleteRecursively()
file.parentFile.mkdirs()

val remoteUrl = AAPT2_DOWNLOAD_URL.format(DEFAULT_VERSION, arch)
DownloadUtils.doDownload(file, remoteUrl, checksum, logger)
}
Expand Down

0 comments on commit 6d20a72

Please sign in to comment.