diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c7b1ff51f..2ba4587ee 100755 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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( diff --git a/build-logic/ide/src/main/java/ProjectConfig.kt b/build-logic/ide/src/main/java/ProjectConfig.kt index da3ee18a3..c14d13a07 100644 --- a/build-logic/ide/src/main/java/ProjectConfig.kt +++ b/build-logic/ide/src/main/java/ProjectConfig.kt @@ -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() { diff --git a/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/conf/AndroidModuleConf.kt b/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/conf/AndroidModuleConf.kt index a5e5a55fa..105629cb4 100644 --- a/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/conf/AndroidModuleConf.kt +++ b/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/conf/AndroidModuleConf.kt @@ -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: +// - /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 /scripts/setup_fdroid_build.sh + // + // IMPORTANT: When changing the configuration here, make sure to update the following file: + // - /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 { diff --git a/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/util/SigningKeyUtils.kt b/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/util/SigningKeyUtils.kt index aac464b39..0104a22ac 100644 --- a/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/util/SigningKeyUtils.kt +++ b/build-logic/ide/src/main/java/com/itsaky/androidide/plugins/util/SigningKeyUtils.kt @@ -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() diff --git a/build-logic/ide/src/main/java/config.kt b/build-logic/ide/src/main/java/config.kt index ef317dff3..167f80d53 100644 --- a/build-logic/ide/src/main/java/config.kt +++ b/build-logic/ide/src/main/java/config.kt @@ -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 get() = rootProject.layout.buildDirectory.file("signing/signing-key.jks") \ No newline at end of file diff --git a/.tools/download_key.sh b/scripts/download_key.sh similarity index 100% rename from .tools/download_key.sh rename to scripts/download_key.sh diff --git a/.tools/run_instrumentation_tests.sh b/scripts/run_instrumentation_tests.sh similarity index 100% rename from .tools/run_instrumentation_tests.sh rename to scripts/run_instrumentation_tests.sh diff --git a/scripts/setup_fdroid_build.sh b/scripts/setup_fdroid_build.sh new file mode 100644 index 000000000..caa990e66 --- /dev/null +++ b/scripts/setup_fdroid_build.sh @@ -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 . +# + +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 \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index e64e6e468..9876e03ec 100755 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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/") } } }