Refactor(Gradle): Optimize build script
Optimize version number rule. Optimize generated file name.
This commit is contained in:
@@ -1,8 +1,14 @@
|
|||||||
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
|
|
||||||
import com.mikepenz.aboutlibraries.plugin.AboutLibrariesTask
|
import com.mikepenz.aboutlibraries.plugin.AboutLibrariesTask
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
|
|
||||||
|
val localDateTime: LocalDateTime = LocalDateTime.now(ZoneOffset.UTC)
|
||||||
|
val baseVersionCode = 1
|
||||||
|
val baseVersionName = "0.0.0"
|
||||||
|
|
||||||
val keystoreProperties = rootProject.file("keystore.properties").run {
|
val keystoreProperties = rootProject.file("keystore.properties").run {
|
||||||
if (!exists()) {
|
if (!exists()) {
|
||||||
null
|
null
|
||||||
@@ -35,13 +41,21 @@ android {
|
|||||||
applicationId = "top.fatweb.oxygen.toolbox"
|
applicationId = "top.fatweb.oxygen.toolbox"
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 1
|
versionCode = baseVersionCode
|
||||||
versionName = "1.0.0-SNAPSHOT"
|
versionName = "$baseVersionName${
|
||||||
|
if (baseVersionCode % 100 != 0) ".${
|
||||||
|
localDateTime.format(
|
||||||
|
DateTimeFormatter.ofPattern("yyMMdd")
|
||||||
|
)
|
||||||
|
}" else ""
|
||||||
|
}"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables {
|
vectorDrawables {
|
||||||
useSupportLibrary = true
|
useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setProperty("archivesBaseName", "$applicationId-v$versionName($versionCode)")
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
@@ -67,15 +81,6 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all {
|
|
||||||
outputs.all {
|
|
||||||
if (this is BaseVariantOutputImpl) {
|
|
||||||
outputFileName =
|
|
||||||
"${applicationId}-v${defaultConfig.versionName}(${defaultConfig.versionCode})-${buildType.name}.${outputFile.extension}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
// Flag to enable support for the new language APIs
|
// Flag to enable support for the new language APIs
|
||||||
isCoreLibraryDesugaringEnabled = true
|
isCoreLibraryDesugaringEnabled = true
|
||||||
|
|||||||
Reference in New Issue
Block a user