diff --git a/.nyx.yml b/.nyx.yml
index 4b1c0f5c1..5232d21b0 100644
--- a/.nyx.yml
+++ b/.nyx.yml
@@ -77,3 +77,9 @@ services:
REPOSITORY_OWNER: "AndroidIDEOfficial"
REPOSITORY_NAME: "AndroidIDE"
AUTHENTICATION_TOKEN: "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}"
+
+git:
+ remotes:
+ origin:
+ user: '{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}'
+ password: ''
diff --git a/build-logic/ide/src/main/java/FDroidConfig.kt b/build-logic/ide/src/main/java/FDroidConfig.kt
new file mode 100644
index 000000000..1b29165a6
--- /dev/null
+++ b/build-logic/ide/src/main/java/FDroidConfig.kt
@@ -0,0 +1,62 @@
+import org.gradle.api.Project
+import java.io.File
+
+/*
+ * 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 .
+ */
+
+/**
+ * @author Akash Yadav
+ */
+object FDroidConfig {
+
+ var hasRead: Boolean = false
+ private set
+
+ var isFDroidBuild: Boolean = false
+ private set
+
+ var fDroidVersionName: String? = null
+ private set
+
+ var fDroidVersionCode: Int? = null
+ private set
+
+ const val PROP_FDROID_BUILD = "ide.build.fdroid"
+ const val PROP_FDROID_BUILD_VERSION = "ide.build.fdroid.version"
+ const val PROP_FDROID_BUILD_VERCODE = "ide.build.fdroid.vercode"
+
+ fun load(project: Project) {
+ val propsFile = File(project.rootDir, "fdroid.properties")
+ if (!propsFile.exists() || !propsFile.isFile) {
+ hasRead = true
+ isFDroidBuild = false
+ return
+ }
+
+ val properties = propsFile.let { props ->
+ java.util.Properties().also {
+ it.load(props.reader())
+ }
+ }
+
+ hasRead = true
+ isFDroidBuild = properties.getProperty(PROP_FDROID_BUILD, null).toBoolean()
+
+ fDroidVersionName = properties.getProperty(PROP_FDROID_BUILD_VERSION, null)
+ fDroidVersionCode = properties.getProperty(PROP_FDROID_BUILD_VERCODE, null)?.toInt()
+ }
+}
\ No newline at end of file
diff --git a/build-logic/ide/src/main/java/ProjectConfig.kt b/build-logic/ide/src/main/java/ProjectConfig.kt
index c14d13a07..2b374661d 100644
--- a/build-logic/ide/src/main/java/ProjectConfig.kt
+++ b/build-logic/ide/src/main/java/ProjectConfig.kt
@@ -38,7 +38,12 @@ 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"
+ get() {
+ if (!FDroidConfig.hasRead) {
+ FDroidConfig.load(this)
+ }
+ return FDroidConfig.isFDroidBuild
+ }
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 dedeed444..77c033652 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
@@ -78,19 +78,12 @@ fun Project.configureAndroidModule(
"\"${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 {
- flavorsAbis.forEach { (abi, verCodeIncrement) ->
- val flavor = create(abi)
- flavor.versionNameSuffix = "-${abi}"
- flavor.versionCode = 100 * projectVersionCode + verCodeIncrement
- }
+ 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.gradle.kts b/build.gradle.kts
index 634087658..5f1ce1a63 100755
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -18,12 +18,11 @@
@file:Suppress("UnstableApiUsage")
import com.itsaky.androidide.plugins.AndroidIDEPlugin
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.itsaky.androidide.plugins.conf.configureAndroidModule
import com.itsaky.androidide.plugins.conf.configureJavaModule
import com.itsaky.androidide.plugins.conf.configureMavenPublish
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("build-logic.root-project")
alias(libs.plugins.android.application) apply false
@@ -49,8 +48,12 @@ subprojects {
project.group = BuildConfig.packageName
project.version = rootProject.version
- plugins.withId("com.android.application") { configureAndroidModule(libs.androidx.lib.desugaring.get()) }
- plugins.withId("com.android.library") { configureAndroidModule(libs.androidx.lib.desugaring.get()) }
+ plugins.withId("com.android.application") {
+ configureAndroidModule(libs.androidx.lib.desugaring.get())
+ }
+ plugins.withId("com.android.library") {
+ configureAndroidModule(libs.androidx.lib.desugaring.get())
+ }
plugins.withId("java-library") { configureJavaModule() }
plugins.withId("com.vanniktech.maven.publish.base") { configureMavenPublish() }
diff --git a/scripts/setup_fdroid_build.sh b/scripts/setup_fdroid_build.sh
deleted file mode 100755
index e56c485ee..000000000
--- a/scripts/setup_fdroid_build.sh
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/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" # Format: $major.$minor.$patch-$type-$abi e.g. 2.7.0-beta-arm64
-versionCode="$2" # Format: $major$minor$patch e.g. 270
-
-# Android defaultConfig
-DEFCONFIG_REPLACE_BEGIN="FDROID_PREBUILD_DEFCONFIG_REPLACE_BEGIN"
-DEFCONFIG_REPLACE_END="FDROID_PREBUILD_DEFCONFIG_REPLACE_END"
-
-# settings.gradle
-SETTINGS_GRADLE_REPLACE_BEGIN="FDROID_PREBUILD_SETTINGS_REPLACE_BEGIN"
-SETTINGS_GRADLE_REPLACE_END="FDROID_PREBUILD_SETTINGS_REPLACE_END"
-
-# Android productFlavors
-FLAVORS_INSERT="FDROID_PREBUILD_FLAVORS_INSERT"
-
-# File to update
-build_gradle="build.gradle.kts"
-gradle_props="../fdroid.properties"
-settings_gradle="../settings.gradle.kts"
-
-flavorDef="productFlavors {\n"
-
-i=1
-for arch in arm64-v8a armeabi-v7a x86_64; do
- flavorDef+="create(\"$arch\") { \n"
- flavorDef+=" versionNameSuffix = \"-fdroid\" \n"
- flavorDef+=" versionCode = 100 * $versionCode + $i \n"
- flavorDef+="}\n"
- i=$((i + 1))
-done
-
-flavorDef+="}"
-
-# settings.gradle
-settingsDef=$(
- cat <<-END
-val propsFile = File(rootDir, "fdroid.properties")
-if (!propsFile.exists() || !propsFile.isFile) {
- throw GradleException("fdroid.properties file does not exist or is not a file")
-}
-
-val properties = propsFile.let { props ->
- java.util.Properties().also {
- it.load(props.reader())
- }
- }
-
-val isFDroidBuild = properties.getProperty("ide.build.fdroid", "true").toBoolean()
-
-val fdroidVersionName = requireNotNull(properties.getProperty("ide.build.fdroid.version", null)) {
- "'ide.build.fdroid' is 'true' but no 'ide.build.fdroid.version' is defined!"
-}
-
-gradle.rootProject { project.setProperty("version", fdroidVersionName) }
-END
-
-)
-
-# Replace properties in defaultConfig with constants
-sed -i "/\/\/ @@$DEFCONFIG_REPLACE_BEGIN@@/,/\/\/ @@$DEFCONFIG_REPLACE_END@@/c\
- applicationId = \"com.itsaky.androidide\" \n \
- versionName = \"$versionName\" \n \
- versionCode = $versionCode \n" $build_gradle
-
-# Add product flavors
-sed -i "/\/\/ @@$FLAVORS_INSERT@@/c\
- $flavorDef" $build_gradle
-
-# Remove the Nyx plugin from settings.gradle
-awk -v begin="$SETTINGS_GRADLE_REPLACE_BEGIN" -v end="$SETTINGS_GRADLE_REPLACE_END" -v replacement="$settingsDef" '
- $0 ~ ("// @@" begin "@@") {
- printing = 1;
- print replacement;
- next;
- }
- printing && $0 ~ ("// @@" end "@@") {
- printing = 0;
- next;
- }
- !printing
-' $settings_gradle >temp_settings.gradle && mv temp_settings.gradle $settings_gradle
-
-# Write Gradle properties
-echo "ide.build.fdroid=true" >"$gradle_props"
-echo "ide.build.fdroid.version=${versionName}" >>"$gradle_props"
-echo "ide.build.fdroid.vercode=${versionCode}" >>"$gradle_props"
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 49e1ea78a..eff52a06f 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -11,23 +11,24 @@ pluginManagement {
}
}
-// DO NOT REMOVE THESE COMMENTS!
-// @@FDROID_PREBUILD_SETTINGS_REPLACE_BEGIN@@
-plugins {
- id("com.mooltiverse.oss.nyx") version "2.5.1"
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath("com.mooltiverse.oss.nyx:gradle:2.5.1")
+ }
}
-// DO NOT REPLACE WITH IMPORT!!
-extensions.configure {
- git {
- remotes.register("origin") {
- user.set("{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}")
- password.set("")
- }
+FDroidConfig.load(rootDir)
+
+if (FDroidConfig.hasRead && FDroidConfig.isFDroidBuild) {
+ gradle.rootProject { project.setProperty("version", FDroidConfig.fDroidVersionName!!) }
+} else {
+ apply {
+ plugin("com.mooltiverse.oss.nyx")
}
- configurationFile.set(".nyx.yml")
}
-// @@FDROID_PREBUILD_SETTINGS_REPLACE_END@@
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
@@ -108,3 +109,43 @@ include(
":testing:tooling",
":testing:unit",
)
+
+object FDroidConfig {
+
+ var hasRead: Boolean = false
+ private set
+
+ var isFDroidBuild: Boolean = false
+ private set
+
+ var fDroidVersionName: String? = null
+ private set
+
+ var fDroidVersionCode: Int? = null
+ private set
+
+ const val PROP_FDROID_BUILD = "ide.build.fdroid"
+ const val PROP_FDROID_BUILD_VERSION = "ide.build.fdroid.version"
+ const val PROP_FDROID_BUILD_VERCODE = "ide.build.fdroid.vercode"
+
+ fun load(rootDir: File) {
+ val propsFile = File(rootDir, "fdroid.properties")
+ if (!propsFile.exists() || !propsFile.isFile) {
+ hasRead = true
+ isFDroidBuild = false
+ return
+ }
+
+ val properties = propsFile.let { props ->
+ java.util.Properties().also {
+ it.load(props.reader())
+ }
+ }
+
+ hasRead = true
+ isFDroidBuild = properties.getProperty(PROP_FDROID_BUILD, null).toBoolean()
+
+ fDroidVersionName = properties.getProperty(PROP_FDROID_BUILD_VERSION, null)
+ fDroidVersionCode = properties.getProperty(PROP_FDROID_BUILD_VERCODE, null)?.toInt()
+ }
+}
\ No newline at end of file