Skip to content

Commit

Permalink
Add version code check
Browse files Browse the repository at this point in the history
The check will fail unless the version code is less than 30000000.
This means that all version codes up until the year 2030 are valid.
The check runs before the preBuild task.
  • Loading branch information
albin-mullvad committed Nov 10, 2023
1 parent e29a55c commit dc957ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ android {
}

project.tasks.preBuild.dependsOn("ensureJniDirectoryExist")
project.tasks.preBuild.dependsOn("ensureValidVersionCode")
}

androidComponents {
Expand Down Expand Up @@ -265,6 +266,17 @@ tasks.register("ensureJniDirectoryExist") {
}
}

// This is a safety net to avoid generating too big version codes, since that could potentially be
// hard and inconvenient to recover from.
tasks.register("ensureValidVersionCode") {
doLast {
val versionCode = project.android.defaultConfig.versionCode!!
if (versionCode >= MAX_ALLOWED_VERSION_CODE) {
throw GradleException("Bad version code: $versionCode")
}
}
}

tasks.create("printVersion") {
doLast {
println("versionCode=${project.android.defaultConfig.versionCode}")
Expand Down
2 changes: 2 additions & 0 deletions android/buildSrc/src/main/kotlin/VerificationConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This value represent a version code that would be generated from and after year 2030.
const val MAX_ALLOWED_VERSION_CODE = 30000000

0 comments on commit dc957ab

Please sign in to comment.