Skip to content

Commit

Permalink
fix: Change app versioning for fdroid #WPB-11429 (#3501)
Browse files Browse the repository at this point in the history
Co-authored-by: Yamil Medina <[email protected]>
  • Loading branch information
m-zagorski and yamilmedina authored Oct 15, 2024
1 parent d4bd0f9 commit 3f305a7
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-fdroid-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ jobs:
run: chmod +x ./gradlew
- name: build prod flavour APK
run:
./gradlew app:assembleFdroidCompatrelease
./gradlew app:assembleFdroidCompatrelease \
-PisFDroidRelease=true
env:
KEYSTORE_FILE_PATH_DEBUG: ${{ vars.KEYSTORE_FILE_PATH }}
KEYSTORE_FILE_PATH_RELEASE: ${{ vars.KEYSTORE_FILE_PATH }}
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/kotlin/com/wire/android/util/AppNameUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,21 @@ import com.wire.android.BuildConfig

internal object AppNameUtil {

/**
* We are supporting two different versions of app name:
* - fDroid - this contains only version ie. 4.1.0 and we need to add leastSignificantVersionCode and build flavor
* - other - this contains version, leastSignificantVersionCode and a build flavor out of the box
*
* We can simply distinguish those by checking if current [BuildConfig.VERSION_NAME] contains `-` char.
*/
fun createAppName(): String {
return "${BuildConfig.VERSION_NAME}-${leastSignificantVersionCode()}-${BuildConfig.FLAVOR}"
val currentAppName = BuildConfig.VERSION_NAME

return if (currentAppName.contains("-")) {
currentAppName
} else {
"${BuildConfig.VERSION_NAME}-${leastSignificantVersionCode()}-${BuildConfig.FLAVOR}"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,25 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {

extensions.configure<ApplicationExtension> {
// TODO: Handle flavors. Currently implemented in `variants.gradle.kts` script

namespace = AndroidApp.id
configureKotlinAndroid(this)

val isFDroidRelease = (project.properties["isFDroidRelease"] as? String)?.toBoolean() ?: false

defaultConfig {
AndroidApp.setRootDir(projectDir)
AndroidApp.setRootDir(project.projectDir)

val resolvedVersionName = if (isFDroidRelease) {
AndroidApp.versionName
} else {
"${AndroidApp.versionName}-${AndroidApp.leastSignificantVersionCode}"
}

applicationId = AndroidApp.id
defaultConfig.targetSdk = AndroidSdk.target
versionCode = AndroidApp.versionCode
versionName = AndroidApp.versionName
versionName = resolvedVersionName
setProperty("archivesBaseName", "$applicationId-v$versionName")
}

Expand Down
19 changes: 19 additions & 0 deletions build-logic/plugins/src/main/kotlin/AndroidCoordinates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ object AndroidApp {
fun setRootDir(rootDir: File) {
this._rootDir = rootDir
}

/**
* The last 5 digits of the VersionCode. From 0 to 99_999.
* It's an [Int], so it can be less than 5 digits when doing [toString], of course.
* Considering versionCode bumps every 5min, these are
* 288 per day
* 8640 per month
* 51840 per semester
* 103_680 per year. ~99_999
*
* So it takes almost a whole year until it rotates back.
* It's very unlikely that two APKs with the same version (_e.g._ 4.8.0)
* will have the same [leastSignificantVersionCode],
* unless they are build almost one year apart.
*/
@Suppress("MagicNumber")
val leastSignificantVersionCode by lazy {
versionCode % 100_000
}
}
8 changes: 7 additions & 1 deletion buildSrc/src/main/kotlin/flavor/ProductFlavors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object FlavorDimensions {
sealed class ProductFlavors(
val buildName: String,
val appName: String,
val versionNameSuffix: String = "-${buildName}",
val dimensions: String = FlavorDimensions.DEFAULT,
val shareduserId: String = ""
) {
Expand All @@ -35,7 +36,12 @@ sealed class ProductFlavors(
object Beta : ProductFlavors("beta", "Wire Beta")
object Internal : ProductFlavors("internal", "Wire Internal")
object Production : ProductFlavors("prod", "Wire", shareduserId = "com.waz.userid")
object Fdroid : ProductFlavors("fdroid", "Wire", shareduserId = "com.waz.userid")
object Fdroid : ProductFlavors(
buildName = "fdroid",
appName = "Wire",
shareduserId = "com.waz.userid",
versionNameSuffix = ""
)

companion object {
val all: Collection<ProductFlavors> = setOf(
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/scripts/variants.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fun NamedDomainObjectContainer<ApplicationProductFlavor>.createAppFlavour(
create(flavour.buildName) {
dimension = flavour.dimensions
applicationId = flavorApplicationId
versionNameSuffix = flavour.versionNameSuffix
resValue("string", "app_name", flavour.appName)
manifestPlaceholders["sharedUserId"] = sharedUserId
manifestPlaceholders["appAuthRedirectScheme"] = flavorApplicationId
Expand Down
2 changes: 1 addition & 1 deletion docker-agent/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fi

if [ "$BUILD_CLIENT" = true ] ; then
echo "Compiling the client with Flavor:${CUSTOM_FLAVOR} and BuildType:${BUILD_TYPE}"
./gradlew ${buildOption}assemble${FLAVOR_TYPE}${BUILD_TYPE}
./gradlew ${buildOption}assemble${FLAVOR_TYPE}${BUILD_TYPE} -PisFDroidRelease=true
else
echo "Building the client will be skipped"
fi
Expand Down

0 comments on commit 3f305a7

Please sign in to comment.