11import com.android.build.api.artifact.SingleArtifact
22import com.android.build.api.variant.FilterConfiguration
3+ import com.android.build.api.variant.impl.VariantOutputImpl
34import com.google.android.gms.oss.licenses.plugin.DependencyTask
45import com.google.gms.googleservices.GoogleServicesPlugin
56
67plugins {
78 alias(libs.plugins.android.application)
8- alias(libs.plugins.kotlin.android)
99 alias(libs.plugins.kotlin.compose)
1010 alias(libs.plugins.google.oss.licenses)
1111 alias(libs.plugins.google.services)
@@ -20,8 +20,8 @@ android {
2020 applicationId = " org.monogram"
2121 minSdk = 25
2222 targetSdk = 36
23- versionCode = 6
24- versionName = " 0.0.6 "
23+ versionCode = 7
24+ versionName = " 0.0.7 "
2525 }
2626
2727 splits {
@@ -45,10 +45,16 @@ android {
4545 getDefaultProguardFile(" proguard-android-optimize.txt" ),
4646 " proguard-rules.pro"
4747 )
48+ buildFeatures {
49+ resValues = true
50+ }
4851 signingConfig = signingConfigs.getByName(" debug" )
4952 resValue(" string" , " app_name" , " MonoGram" )
5053 }
5154 debug {
55+ buildFeatures {
56+ resValues = true
57+ }
5258 applicationIdSuffix = " .debug"
5359 isMinifyEnabled = false
5460 resValue(" string" , " app_name" , " MonoGram Debug" )
@@ -58,54 +64,56 @@ android {
5864 sourceCompatibility = JavaVersion .VERSION_21
5965 targetCompatibility = JavaVersion .VERSION_21
6066 }
61- kotlin {
62- jvmToolchain(21 )
63- }
6467 buildFeatures {
6568 compose = true
6669 }
6770}
6871
6972androidComponents {
7073 onVariants { variant ->
74+ if (variant.buildType != " release" ) return @onVariants
75+
76+ variant.outputs.forEach { output ->
77+ val variantOutput = output as ? VariantOutputImpl ? : return @forEach
78+ val abi = variantOutput.filters.find {
79+ it.filterType == FilterConfiguration .FilterType .ABI
80+ }?.identifier ? : " universal"
81+ val versionName = variantOutput.versionName.orNull ? : " unknown"
82+
83+ variantOutput.outputFileName.set(
84+ " monogram-$abi -$versionName -${variant.buildType} .apk"
85+ )
86+ }
87+
7188 val apkDirProvider = variant.artifacts.get(SingleArtifact .APK )
72- val artifactsLoader = variant.artifacts.getBuiltArtifactsLoader()
73-
74- val renameTask = tasks.register(" rename${variant.name.capitalize()} Apk" ) {
75- inputs.dir(apkDirProvider)
76-
77- doLast {
78- val builtArtifacts = artifactsLoader.load(apkDirProvider.get())!!
79- val targetDir = apkDirProvider.get().asFile
80-
81- builtArtifacts.elements.forEach { artifact ->
82- val abi = artifact.filters.find {
83- it.filterType == FilterConfiguration .FilterType .ABI
84- }?.identifier ? : " universal"
85- val versionName = artifact.versionName
86- val versionCode = artifact.versionCode
87- val buildType = variant.buildType
88-
89- val originalApk = File (artifact.outputFile)
90- val targetFile = File (
91- targetDir,
92- " monogram-$abi -${versionName} (${versionCode} )-${buildType} .apk"
93- )
94-
95- originalApk.copyTo(targetFile, overwrite = true )
96- }
89+
90+ val capitalizedVariantName = variant.name.replaceFirstChar {
91+ if (it.isLowerCase()) it.titlecase() else it.toString()
92+ }
93+
94+ val copyTask = tasks.register<Sync >(" copy${capitalizedVariantName} Apk" ) {
95+ from(apkDirProvider)
96+ include(" *.apk" )
97+ into(layout.projectDirectory.dir(" releases" ))
98+
99+ doFirst {
100+ destinationDir.mkdirs()
101+ destinationDir.listFiles()
102+ ?.filter { it.isFile && it.extension == " apk" && it.name.startsWith(" monogram-" ) }
103+ ?.forEach { it.delete() }
97104 }
98105 }
99106
100- project.tasks.matching { it.name == " assemble${variant.name.capitalize() } " }.configureEach {
101- finalizedBy(renameTask )
107+ project.tasks.matching { it.name == " assemble${capitalizedVariantName } " }.configureEach {
108+ finalizedBy(copyTask )
102109 }
103110 }
104111}
105112
106113dependencies {
107114 implementation(platform(libs.androidx.compose.bom))
108115 implementation(libs.bundles.androidx.compose)
116+ implementation(libs.androidx.core.splashscreen)
109117
110118 implementation(libs.bundles.decompose)
111119 implementation(libs.bundles.koin)
@@ -131,14 +139,20 @@ dependencies {
131139
132140tasks.withType(DependencyTask ::class .java).configureEach {
133141 if (name == " debugOssDependencyTask" ) {
134- val releaseTaskProvider = project.tasks.named<DependencyTask >(" releaseOssDependencyTask" )
142+ val releaseJsonProvider =
143+ layout.buildDirectory.file(" generated/third_party_licenses/release/dependencies.json" )
144+ val debugJsonProvider =
145+ layout.buildDirectory.file(" generated/third_party_licenses/debug/dependencies.json" )
135146
136- dependsOn(releaseTaskProvider )
147+ dependsOn(" releaseOssDependencyTask " )
137148
138149 doLast {
139- val releaseJson = releaseTaskProvider.get().dependenciesJson.get().asFile
140- val debugJson = dependenciesJson.get().asFile
141- if (releaseJson.exists()) releaseJson.copyTo(debugJson, overwrite = true )
150+ val releaseJson = releaseJsonProvider.get().asFile
151+ val debugJson = debugJsonProvider.get().asFile
152+ if (releaseJson.exists()) {
153+ debugJson.parentFile?.mkdirs()
154+ releaseJson.copyTo(debugJson, overwrite = true )
155+ }
142156 }
143157 }
144158}
0 commit comments