diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 75be75443..b1ce3b2f2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,7 +18,7 @@ android { base.archivesName.set(apkPrefix) resValue("string", "app_name", "Kiwix") resValue("string", "app_search_string", "Search Kiwix") - versionCode = GenerateVersionCode.getVersionCode() + versionCode = "".getVersionCode() versionName = generateVersionName() manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE" } @@ -85,7 +85,7 @@ task("generateVersionCodeAndName") { file.printWriter().use { it.print( "${generateVersionName()}\n" + - "7${GenerateVersionCode.getVersionCode()}" + "7" + "".getVersionCode() ) } } diff --git a/buildSrc/src/main/kotlin/GenerateVersionCode.kt b/buildSrc/src/main/kotlin/GenerateVersionCode.kt deleted file mode 100644 index 7cf277771..000000000 --- a/buildSrc/src/main/kotlin/GenerateVersionCode.kt +++ /dev/null @@ -1,40 +0,0 @@ -import java.time.LocalDate -import java.time.temporal.ChronoUnit - -/* - * Kiwix Android - * Copyright (c) 2024 Kiwix - * This program 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. - * - * This program 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 this program. If not, see . - * - */ - -object GenerateVersionCode { - fun getVersionCode(): Int { - // the date when the automatic version code generation started - val lastDate = LocalDate.of(2024, 7, 17) - - // Calculate the number of days between the lastDate and today's date. - // This gives us the total number of days since the last version code was set. - val daysDifference = ChronoUnit.DAYS.between(lastDate, LocalDate.now()).toInt() - - // Base version code. This is the version code of the last release uploaded to the Play Store. - // We use this as the starting point for generating new version codes automatically. - val baseVersionCode = 231101 - - // Generate and return the new version code. - // The new version code is calculated by adding the number of days since lastDate - // to the base version code. This creates a unique version code for each day. - return baseVersionCode + daysDifference - } -} diff --git a/buildSrc/src/main/kotlin/VersionCodeGenerator.kt b/buildSrc/src/main/kotlin/VersionCodeGenerator.kt new file mode 100644 index 000000000..269b31198 --- /dev/null +++ b/buildSrc/src/main/kotlin/VersionCodeGenerator.kt @@ -0,0 +1,38 @@ +import java.time.LocalDate +import java.time.temporal.ChronoUnit + +/* + * Kiwix Android + * Copyright (c) 2024 Kiwix + * This program 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. + * + * This program 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 this program. If not, see . + * + */ + +fun String.getVersionCode(): Int { + // the date when the automatic version code generation started + val lastDate = LocalDate.of(2024, 7, 17) + + // Calculate the number of days between the lastDate and today's date. + // This gives us the total number of days since the last version code was set. + val daysDifference = ChronoUnit.DAYS.between(lastDate, LocalDate.now()).toInt() + + // Base version code. This is the version code of the last release uploaded to the Play Store. + // We use this as the starting point for generating new version codes automatically. + val baseVersionCode = 231101 + + // Generate and return the new version code. + // The new version code is calculated by adding the number of days since lastDate + // to the base version code. This creates a unique version code for each day. + return baseVersionCode + daysDifference +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 6ff5ca2ae..383595731 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -21,7 +21,7 @@ apply(plugin = "com.jakewharton.butterknife") android { defaultConfig { - buildConfigField("long", "VERSION_CODE", "${GenerateVersionCode.getVersionCode()}") + buildConfigField("long", "VERSION_CODE", "".getVersionCode().toString()) } buildTypes { getByName("release") {