Play 스토어 심사에 낸 1(0.1) 빌드와 같은 코드 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
4.4 KiB
Kotlin
89 lines
4.4 KiB
Kotlin
import com.google.android.wearable.watchface.validator.client.DwfValidatorFactory
|
|
|
|
// 스킨 APK 검증·토큰 발급기 (Watch Face Push). 의존성 하나가 jitpack 에만 있다
|
|
buildscript {
|
|
repositories {
|
|
google()
|
|
mavenCentral()
|
|
maven("https://jitpack.io") { content { includeGroup("com.github.xgouchet") } }
|
|
}
|
|
dependencies { classpath("com.google.android.wearable.watchface.validator:validator-push:1.0.0-alpha09") }
|
|
}
|
|
|
|
plugins {
|
|
id("com.android.application")
|
|
id("org.jetbrains.kotlin.plugin.compose")
|
|
}
|
|
|
|
android {
|
|
namespace = "kr.o2o.nalssigak"
|
|
compileSdk = 37
|
|
|
|
defaultConfig {
|
|
applicationId = "kr.o2o.nalssigak"
|
|
// Wear OS 6+ 만. 앱 설치 때 스킨을 같이 깔고 시계 화면으로 바꾸는 Watch Face Push 가 API 36 부터다
|
|
minSdk = 36
|
|
targetSdk = 36
|
|
versionCode = 1
|
|
versionName = "0.1"
|
|
// 앱에 실은 스킨 버전. 워치에 깔린 스킨이 이보다 낮으면 앱이 바꿔 끼운다 (MainActivity.useSkin)
|
|
buildConfigField("int", "SKIN_VERSION", providers.gradleProperty("NALSSIGAK_SKIN_VERSION").get())
|
|
}
|
|
buildTypes {
|
|
// 에뮬레이터에서 본 맥의 로컬 백엔드 (compose 포트 9810)
|
|
debug { buildConfigField("String", "API_BASE", "\"http://10.0.2.2:9810\"") }
|
|
// 운영 서버 https 주소는 -PNALSSIGAK_API_BASE=… 또는 ~/.gradle/gradle.properties 로
|
|
release {
|
|
buildConfigField("String", "API_BASE", "\"${providers.gradleProperty("NALSSIGAK_API_BASE").getOrElse("")}\"")
|
|
isMinifyEnabled = true
|
|
isShrinkResources = true
|
|
}
|
|
}
|
|
// 오픈소스 라이선스 전문을 앱에 같이 싣는다 (MIT·OFL 고지 조건)
|
|
sourceSets["main"].assets.directories.add("../licenses")
|
|
buildFeatures {
|
|
compose = true
|
|
buildConfig = true
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
implementation("androidx.activity:activity-compose:1.13.0")
|
|
implementation("androidx.wear.compose:compose-material3:1.7.0")
|
|
implementation("androidx.wear.tiles:tiles:1.6.2")
|
|
implementation("androidx.concurrent:concurrent-futures:1.3.0")
|
|
implementation("androidx.wear.watchface:watchface-complications-data-source-ktx:1.3.0")
|
|
implementation("androidx.wear.watchfacepush:watchfacepush:1.0.0")
|
|
}
|
|
|
|
// 앱을 깔면 스킨(:watchface)도 같이 깔리게 한다 (Wear OS 6+ 기본 워치 페이스).
|
|
// 같은 빌드 타입의 스킨 APK 를 assets/default_watchface.apk 로 싣고, 검증 토큰을 문자열 리소스로 만든다
|
|
androidComponents.onVariants { variant ->
|
|
val name = variant.name.replaceFirstChar(Char::titlecase)
|
|
val skinApks = project(":watchface").layout.buildDirectory.dir("outputs/apk/${variant.name}")
|
|
val assetsDir = layout.buildDirectory.dir("generated/skinAssets/${variant.name}")
|
|
val resDir = layout.buildDirectory.dir("generated/skinToken/${variant.name}")
|
|
val appId = variant.applicationId
|
|
variant.sources.assets?.addStaticSourceDirectory(assetsDir.get().asFile.path)
|
|
variant.sources.res?.addStaticSourceDirectory(resDir.get().asFile.path)
|
|
val bundle = tasks.register("bundleSkin$name") {
|
|
dependsOn(":watchface:assemble$name")
|
|
inputs.dir(skinApks)
|
|
outputs.dirs(assetsDir, resDir)
|
|
doLast {
|
|
val apk = skinApks.get().asFile.listFiles { f -> f.extension == "apk" }!!.single()
|
|
// 서명 없는 스킨은 워치가 설치를 거부한다. 업로드 키 설정은 루트 build.gradle.kts 참고
|
|
if (apk.name.endsWith("-unsigned.apk")) throw GradleException("스킨 APK 가 서명되지 않았습니다. ~/.gradle/gradle.properties 에 NALSSIGAK_STORE_* 를 넣고 다시 빌드하세요")
|
|
val result = DwfValidatorFactory.create().validate(apk, appId.get())
|
|
if (result.failures().isNotEmpty()) throw GradleException("스킨 검증 실패: ${result.failures()}")
|
|
apk.copyTo(assetsDir.get().file("default_watchface.apk").asFile, overwrite = true)
|
|
resDir.get().file("values/skin_token.xml").asFile.apply { parentFile.mkdirs() }
|
|
.writeText(
|
|
"""<resources xmlns:tools="http://schemas.android.com/tools">""" +
|
|
"""<string name="default_wf_token" translatable="false" tools:ignore="Typos">${result.validationToken()}</string></resources>""" + "\n"
|
|
)
|
|
}
|
|
}
|
|
afterEvaluate { tasks.named("pre${name}Build") { dependsOn(bundle) } }
|
|
}
|