1515 */
1616
1717plugins {
18- alias(libs.plugins.androidApplication)
19- alias(libs.plugins.jetbrainsKotlinAndroid)
20- alias(libs.plugins.compose.compiler)
18+ id(libs.plugins.androidApplication.get().pluginId)
19+ id(libs.plugins.compose.compiler.get().pluginId)
2120}
2221
2322// Watch Face Push requires API level 36 and above.
@@ -46,9 +45,6 @@ android {
4645 sourceCompatibility = JavaVersion .VERSION_17
4746 targetCompatibility = JavaVersion .VERSION_17
4847 }
49- kotlinOptions {
50- jvmTarget = " 17"
51- }
5248 buildFeatures {
5349 compose = true
5450 }
@@ -57,19 +53,11 @@ android {
5753 excludes + = " /META-INF/{AL2.0,LGPL2.1}"
5854 }
5955 }
60-
61- sourceSets {
62- getByName(" release" ) {
63- assets.srcDirs(layout.buildDirectory.dir(" intermediates/watchfaceAssets/release" ))
64- res.srcDirs(layout.buildDirectory.file(" generated/wfTokenRes/release/res/" ))
65- }
66- getByName(" debug" ) {
67- assets.srcDirs(layout.buildDirectory.dir(" intermediates/watchfaceAssets/debug" ))
68- res.srcDirs(layout.buildDirectory.file(" generated/wfTokenRes/debug/res/" ))
69- }
70- }
7156}
7257
58+ kotlin {
59+ jvmToolchain(17 )
60+ }
7361
7462val mainAppNamespace = Attribute .of(" wfp.app.namespace" , String ::class .java)
7563// Define configurations that allows this app to include the sample watch faces in their assets
@@ -141,25 +129,35 @@ dependencies {
141129// of the default watch face. This token is read from the marketplace manifest
142130// upon installation, so that the default watch face can be installed.
143131
144- afterEvaluate {
145- android.applicationVariants.all {
146- val capsVariantName = name.replaceFirstChar(Char ::titlecase)
147- val variantName = name
148- val copyTask = tasks.register(" copyWatchFaceAssets$capsVariantName " , Copy ::class .java) {
149- from(configurations.getByName(" ${variantName} WatchfaceOutput" ).incoming.artifactView {}.files)
150- into(layout.buildDirectory.dir(" intermediates/watchfaceAssets/$variantName " ))
151- duplicatesStrategy = DuplicatesStrategy .EXCLUDE
132+
133+ androidComponents.onVariants { variant ->
134+ val capsVariantName = variant.name.replaceFirstChar(Char ::titlecase)
135+ val variantName = variant.name
136+
137+ val assetsDir = layout.buildDirectory.dir(" intermediates/watchfaceAssets/${variantName} " )
138+ .get().asFile
139+ val resDir = layout.buildDirectory.dir(" generated/wfTokenRes/${variantName} /res/" )
140+ .get().asFile
141+ val tokenFilePath = project.layout.buildDirectory.file(" intermediates/watchfaceAssets/${variantName} /default_watchface_token.txt" )
142+ .get()
143+
144+ variant.sources.assets?.addStaticSourceDirectory(assetsDir.absolutePath)
145+ variant.sources.res?.addStaticSourceDirectory(resDir.absolutePath)
146+
147+ val copyTask = tasks.register(" copyWatchFaceAssets$capsVariantName " , Copy ::class .java) {
148+ from(configurations.getByName(" ${variantName} WatchfaceOutput" ).incoming.artifactView {}.files)
149+ into(assetsDir)
150+ duplicatesStrategy = DuplicatesStrategy .EXCLUDE
151+ }
152+
153+ val tokenResTask =
154+ tasks.register<TokenResourceTask_gradle .TokenResourceTask >(" tokenResTask$capsVariantName " ) {
155+ dependsOn(copyTask)
156+ tokenFile.set(tokenFilePath)
157+ outputDirectory.set(resDir)
152158 }
153159
154- val tokenResTask =
155- tasks.register<TokenResourceTask_gradle .TokenResourceTask >(" tokenResTask$capsVariantName " ) {
156- dependsOn(copyTask)
157- buildVariant.set(variantName)
158- outputDirectory.set(layout.buildDirectory.dir(" generated/wfTokenRes/$variantName " ).get().asFile)
159- }
160- // make sure to run the two defined tasks before doing anything else.
161- // tokenResTask will cause copyWatchFaceAssets to
162- // run as well
160+ afterEvaluate {
163161 tasks.named(" pre${capsVariantName} Build" ).configure {
164162 dependsOn(tokenResTask)
165163 }
0 commit comments