Skip to content

Commit 87a29d8

Browse files
authored
Merge pull request #1355 from android/wfp-gradle-updates
Fixes WFP sample Gradle issues
2 parents 6f1774b + cf988f1 commit 87a29d8

9 files changed

Lines changed: 77 additions & 59 deletions

File tree

WatchFacePush/app/build.gradle.kts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
*/
1616

1717
plugins {
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

7462
val 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
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.google.samples.marketplace.data
2+
3+
class WatchFaceApkCache {
4+
}

WatchFacePush/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import com.android.build.gradle.AppPlugin
2020

2121
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2222
plugins {
23-
alias(libs.plugins.androidApplication) apply false
24-
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
25-
alias(libs.plugins.androidLibrary) apply false
2623
alias(libs.plugins.compose.compiler) apply false
2724
}
2825

@@ -61,7 +58,7 @@ subprojects {
6158
}
6259
val tokenTask =
6360
tasks.register<TokenGenerationTask_gradle.TokenGenerationTask>("assembleToken$variantName") {
64-
dependsOn(assembleTask)
61+
dependsOn(assembleTask!!)
6562

6663
val validatorConfiguration = rootProject.project("app").configurations.getByName("validatorConfiguration")
6764
val mainAppPackageName = validatorConfiguration.attributes.getAttribute(mainAppNamespace)

WatchFacePush/buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ repositories {
3838
}
3939

4040
dependencies {
41-
implementation("com.android.tools.build:gradle-api:8.13.1")
41+
implementation("com.android.tools.build:gradle-api:9.0.0")
4242
implementation("com.google.android.wearable.watchface.validator:validator-push:1.0.0-alpha08")
4343
}

WatchFacePush/buildSrc/src/main/kotlin/TokenResourceTask.gradle.kts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@ import kotlin.text.trimMargin
2525
* Task to create a resource file containing the validation token of the default watch face.
2626
*/
2727
abstract class TokenResourceTask : DefaultTask() {
28-
@get:Input
29-
abstract val buildVariant: Property<String>
28+
@get:InputFile
29+
abstract val tokenFile: RegularFileProperty
3030

3131
@get:OutputDirectory
3232
abstract val outputDirectory: RegularFileProperty
3333

3434
@TaskAction
3535
fun performAction() {
36-
val tokenFile =
37-
project.layout.buildDirectory.file("intermediates/watchfaceAssets/${buildVariant.get()}/default_watchface_token.txt")
38-
.get()
39-
val outputFile = outputDirectory.get().asFile.resolve("res/values/wf_token.xml")
36+
37+
38+
val outputFile = outputDirectory.get().asFile.resolve("values/wf_token.xml")
4039
project.mkdir(outputFile.parent)
4140
val tokenResText = """<resources>
42-
| <string name="default_wf_token">${tokenFile.asFile.readText()}</string>
41+
| <string name="default_wf_token">${tokenFile.get().asFile.readText()}</string>
4342
|</resources>
4443
""".trimMargin()
4544
outputFile.writeText(tokenResText)

WatchFacePush/gradle/libs.versions.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[versions]
2-
agp = "8.13.1"
3-
wear-compose-material3 = "1.5.5"
4-
wear-compose = "1.5.5"
5-
compose-tooling = "1.5.5"
6-
kotlin = "2.1.21"
7-
lifecycleViewmodelKtx = "2.9.4"
8-
composeBom = "2025.11.00"
9-
activityCompose = "1.11.0"
2+
agp = "9.0.0"
3+
wear-compose-material3 = "1.5.6"
4+
wear-compose = "1.5.6"
5+
compose-tooling = "1.5.6"
6+
kotlin = "2.3.0"
7+
lifecycleViewmodelKtx = "2.10.0"
8+
composeBom = "2026.01.00"
9+
activityCompose = "1.12.2"
1010
coreSplashscreen = "1.2.0"
11-
watchfacePush = "1.0.0-alpha01"
12-
horologist = "0.7.14-beta"
11+
watchfacePush = "1.0.0-beta01"
12+
horologist = "0.7.15"
1313

1414
[libraries]
1515
compose-navigation = { module = "androidx.wear.compose:compose-navigation", version.ref = "wear-compose" }

WatchFacePush/samples/defaultwf/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ plugins {
2222

2323
android {
2424
namespace = "com.google.samples.marketplace.watchfacepush.defaultwf"
25-
compileSdk = 35
25+
compileSdk = 36
2626

2727
defaultConfig {
2828
applicationId = "com.google.samples.marketplace.watchfacepush.defaultwf"
@@ -57,5 +57,11 @@ android {
5757
}
5858
}
5959
}
60+
packaging {
61+
resources {
62+
// Exclude all .kotlin_builtins files
63+
excludes += "/**/*.kotlin_builtins"
64+
}
65+
}
6066
}
6167

WatchFacePush/samples/firefly/build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020

2121
android {
2222
namespace = "com.google.samples.marketplace.watchfacepush.firefly"
23-
compileSdk = 35
23+
compileSdk = 36
2424

2525
defaultConfig {
2626
applicationId = "com.google.samples.marketplace.watchfacepush.firefly"
@@ -46,5 +46,12 @@ android {
4646
isMinifyEnabled = true
4747
}
4848
}
49+
50+
packaging {
51+
resources {
52+
// Exclude all .kotlin_builtins files
53+
excludes += "/**/*.kotlin_builtins"
54+
}
55+
}
4956
}
5057

WatchFacePush/samples/river/build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020

2121
android {
2222
namespace = "com.google.samples.marketplace.watchfacepush.river"
23-
compileSdk = 35
23+
compileSdk = 36
2424

2525
defaultConfig {
2626
applicationId = "com.google.samples.marketplace.watchfacepush.river"
@@ -46,5 +46,12 @@ android {
4646
isMinifyEnabled = true
4747
}
4848
}
49+
50+
packaging {
51+
resources {
52+
// Exclude all .kotlin_builtins files
53+
excludes += "/**/*.kotlin_builtins"
54+
}
55+
}
4956
}
5057

0 commit comments

Comments
 (0)