build: update build configuration for F-Droid publication

This commit is contained in:
Akash Yadav
2023-12-31 10:15:21 +05:30
parent d2207b626b
commit d949637198
9 changed files with 106 additions and 18 deletions
+13 -5
View File
@@ -15,23 +15,31 @@ apply {
plugin(AndroidIDEAssetsPlugin::class.java)
}
// The comments starting with @@FDROID_PREBUILD_ are used to insert various configurations
// when building with F-Droid buildserver
// These comments must not be removed
android {
namespace = BuildConfig.packageName
defaultConfig {
// The following comments are used to insert the applicationId, versionName and versionCode
// when building with F-Droid
// @@FDROID_PREBUILD_REPLACE_BEGIN@@
// @@FDROID_PREBUILD_DEFCONFIG_REPLACE_BEGIN@@
applicationId = BuildConfig.packageName
// @@FDROID_PREBUILD_REPLACE_END@@
// @@FDROID_PREBUILD_DEFCONFIG_REPLACE_END@@
vectorDrawables.useSupportLibrary = true
}
// @@FDROID_PREBUILD_FLAVORS_INSERT@@
androidResources {
generateLocaleConfig = true
}
buildTypes { release { isShrinkResources = true } }
buildTypes {
release {
isShrinkResources = true
}
}
packaging {
resources.excludes.addAll(
@@ -34,6 +34,12 @@ object ProjectConfig {
private var shouldPrintVersionName = true
/**
* Whether this build is being executed in the F-Droid build server.
*/
val Project.isFDroidBuild: Boolean
get() = hasProperty(PROP_IDE_BUILD_FDROID) && property(PROP_IDE_BUILD_FDROID) == "true"
val Project.simpleVersionName: String
get() {
@@ -19,6 +19,7 @@ package com.itsaky.androidide.plugins.conf
import BuildConfig
import com.android.build.gradle.BaseExtension
import isFDroidBuild
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import projectVersionCode
@@ -26,12 +27,14 @@ import projectVersionCode
/**
* ABIs for which the product flavors will be created.
* The keys in this map are the names of the product flavors whereas,
* the value for each flavor is a number that will be appended to the base version code of the IDE
* the value for each flavor is a number that will be incremented to the base version code of the IDE
* and set as the version code of that flavor.
*
* For example, if the base version code of the IDE is 270 (for v2.7.0), then for arm64-v8a
* flavor, the version code will be `"270" + "1"` i.e. `"2701".toInt()
* flavor, the version code will be `100 * 270 + 1` i.e. `2701`
*/
// IMPORTANT: When changing the configuration here, make sure to update the following file:
// - <root>/scripts/setup_fdroid_build.sh
private val flavorsAbis = mapOf("arm64-v8a" to 1, "armeabi-v7a" to 2, "x86_64" to 3)
private val disableCoreLibDesugaringForModules = arrayOf(":logsender", ":logger")
@@ -68,16 +71,27 @@ fun Project.configureAndroidModule(
if (":app" == project.path) {
flavorDimensions("default")
productFlavors {
flavorsAbis.forEach { (abi, verCodeSuffix) ->
val flavor = create(abi)
flavor.versionNameSuffix = "-$abi"
flavor.versionCode = "${projectVersionCode}${verCodeSuffix}".toInt()
flavorsAbis.forEach { (abi, _) ->
// the common defaultConfig, not the flavor-specific
defaultConfig.buildConfigField("String",
"FLAVOR_${abi.replace('-', '_').uppercase()}",
"\"${abi}\"")
}
// the common defaultConfig, not the flavor-specific
defaultConfig.buildConfigField("String",
"FLAVOR_${abi.replace('-', '_').uppercase()}",
"\"${abi}\"")
// Do not configure flavorDimensions here when building with F-Droid
// flavor dimensions for F-Droid builds are configured in <root>/scripts/setup_fdroid_build.sh
//
// IMPORTANT: When changing the configuration here, make sure to update the following file:
// - <root>/scripts/setup_fdroid_build.sh
if (!isFDroidBuild) {
productFlavors {
val fdroidSuffix = if (isFDroidBuild) "-fdroid" else ""
flavorsAbis.forEach { (abi, verCodeIncrement) ->
val flavor = create(abi)
flavor.versionNameSuffix = "-${abi}${fdroidSuffix}"
flavor.versionCode = 100 * projectVersionCode + verCodeIncrement
}
}
}
} else {
@@ -58,7 +58,7 @@ object SigningKeyUtils {
logger.info("Downloading signing key...")
val result = exec {
workingDir(rootProject.projectDir)
commandLine("bash", "./.tools/download_key.sh", signingKey.absolutePath, url, user, pass)
commandLine("bash", "./scripts/download_key.sh", signingKey.absolutePath, url, user, pass)
}
result.assertNormalExitValue()
+2
View File
@@ -32,5 +32,7 @@ const val KEY_BIN = "IDE_SIGNING_KEY_BIN"
*/
const val AGP_VERSION_MINIMUM = "7.2.0"
const val PROP_IDE_BUILD_FDROID = "ide.build.fdroid"
val Project.signingKey: Provider<RegularFile>
get() = rootProject.layout.buildDirectory.file("signing/signing-key.jks")
+59
View File
@@ -0,0 +1,59 @@
#!/bin/bash
#
# This file is part of AndroidIDE.
#
# AndroidIDE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# AndroidIDE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
#
set -eu
# Arguments are positional
# 1 - version name
# 2 - version code
versionName="$1"
versionCode="$2"
# Android defaultConfig
DEFCONFIG_REPLACE_BEGIN="FDROID_PREBUILD_DEFCONFIG_REPLACE_BEGIN"
DEFCONFIG_REPLACE_END="FDROID_PREBUILD_DEFCONFIG_REPLACE_END"
# Android productFlavors
FLAVORS_INSERT="FDROID_PREBUILD_FLAVORS_INSERT"
# File to update
target_file="build.gradle.kts"
flavorDef="productFlavors {\n"
i=1
for arch in arm64-v8a armeabi-v7a x86_64; do
flavorDef+="create(\"$arch\") { \n"
flavorDef+=" versionNameSuffix = \"$arch-fdroid\" \n"
flavorDef+=" versionCode = 100 * $versionCode + $i \n"
flavorDef+="}\n"
i=$(( i + 1))
done
flavorDef+="}"
# Replace properties in defaultConfig with constants
sed -i "/\/\/ @@$DEFCONFIG_REPLACE_BEGIN@@/,/\/\/ @@$DEFCONFIG_REPLACE_END@@/c\
applicationId = \"com.itsaky.androidide\" \
versionName = \"$versionName\" \
versionCode = \"$versionCode\"" $target_file
# Add product flavors
sed -i "/\/\/ @@$FLAVORS_INSERT@@/c\
$flavorDef" $target_file
-1
View File
@@ -33,7 +33,6 @@ dependencyResolutionManagement {
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") }
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://repo.gradle.org/gradle/libs-releases/") }
maven { url = uri("https://repo.eclipse.org/content/repositories/lemminx-snapshots/") }
}
}