diff --git a/app/build.gradle b/app/build.gradle index 4418bec3c..10d89221e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -227,28 +227,6 @@ android.applicationVariants.all { variant -> output.versionNameOverride = versionName output.versionCodeOverride = versionCodeOverride } - - // If this is a release build, validate that "versionName" is set - tasks.withType(AppPreBuildTask) { prebuildTask -> - // You can't add a closure to a variant, so we need to look for an early variant-specific type - // of task (AppPreBuildTask is the first) and filter to make sure we're looking at the task for - // this variant that we're currently configuring - if (prebuildTask.variantName != variant.name) { - return - } - - // Append to the task so the first thing it does is run our validation - prebuildTask.doFirst { - if (!project.hasProperty('versionName')) { - throw new RuntimeException("Release builds require the 'versionName' property to be set.\n" + - "If you're using an IDE, set your build variant to be a \"debug\" type.\n" + - "If you're using the command-line, either build a debug variant instead ('./gradlew assembleDebug')\n" + - "\tor continue building the release build and set the \"versionName\" property ('./gradlew -PversionName=<...> assembleNightly').") - // TODO when Android Studio 3.5.0 is prevalent, we can set the "debug" build type as the default - // https://issuetracker.google.com/issues/36988145#comment59 - } - } - } } // ------------------------------------------------------------------------------------------------- diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index d48e3684f..e60c69faa 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -29,9 +29,10 @@ object Config { @JvmStatic fun releaseVersionName(project: Project): String { - // This function is called in the configuration phase, before gradle knows which variants we'll use. - // So, validation that "versionName" has been set happens elsewhere (at time of writing, we staple - // validation to tasks of type "AppPreBuildTask" + // Note: release builds must have the `versionName` set. However, the gradle ecosystem makes this hard to + // ergonomically validate (sometimes IDEs default to a release variant and mysteriously fail due to the + // validation, sometimes devs just need a release build and specifying project properties is annoying in IDEs), + // so instead we'll allow the `versionName` to silently default to an empty string. return if (project.hasProperty("versionName")) project.property("versionName") as String else "" }