Cotton code
138 lines · 7.3 KB · KotlinRaw
import groovy.json.JsonSlurperimport org.jetbrains.kotlin.gradle.dsl.JvmTargetplugins {    id("com.android.library")    kotlin("android")    kotlin("plugin.serialization")    kotlin("plugin.compose")}// The shared faces' specimens draw with what every app carries and nothing more: everyApp's paintings// (apps/loom/materials.json) and the type, laid as an app's assets are (paper/, fonts/).val repo = rootProject.file("../..")val specimens = file("src/test/specimens")val loomPaper = repo.resolve("apps/loom/Sources/CottonPaper")@Suppress("UNCHECKED_CAST")val everyApp = (JsonSlurper().parse(repo.resolve("apps/loom/materials.json")) as Map<String, Any?>)["everyApp"] as List<String>val loomImagesets: List<String> = loomPaper.resolve("Media.xcassets").list()!!.filter { it.endsWith(".imageset") }.map { it.removeSuffix(".imageset") }val specimenAssets = layout.buildDirectory.dir("generated/specimenAssets")val copySpecimenAssets = tasks.register<Sync>("copySpecimenAssets") {    into(specimenAssets)    everyApp.flatMap { n -> if (n.endsWith("*")) loomImagesets.filter { it.startsWith(n.removeSuffix("*")) } else listOf(n) }.forEach { name ->        from(loomPaper.resolve("Media.xcassets/$name.imageset")) { exclude("Contents.json"); into("paper") }    }    from(loomPaper.resolve("Resources/Fonts")) { include("*.ttf"); into("fonts") }}tasks.matching { it.name.startsWith("merge") && it.name.endsWith("UnitTestAssets") }.configureEach { dependsOn(copySpecimenAssets) }// THE SHARED SHELL: every Cotton app on Android draws what the one Rust core// answers (shell.home, fan, deck, opened, plus, input, lines) through this// module; an app adds only its faces and its platform parts (ShellParts).android {    namespace = "com.cottondb.shell"    compileSdk = 36    defaultConfig {        minSdk = 28        consumerProguardFiles("consumer-rules.pro")    }    // aidl: Cotton Voice's binder contract (src/main/aidl/com/cottondb/voice), served by the voice app and called by every other.    buildFeatures { compose = true; aidl = true }    lint {        // Transfers runs WorkManager's foreground service, whose dataSync type each app that keeps files declares in        // its own manifest (app/src/<app>/AndroidManifest.xml); this library has no manifest entry of its own, so the        // check is the app's (`:app:lint<App>DevDebug` reads the merged manifest), not the shell's.        disable += "SpecifyForegroundServiceType"    }    compileOptions {        sourceCompatibility = JavaVersion.VERSION_17        targetCompatibility = JavaVersion.VERSION_17        isCoreLibraryDesugaringEnabled = true    }    testOptions {        unitTests.isReturnDefaultValues = true        // The specimens (shell/src/test/specimens): Robolectric draws each shared face with the real paintings and        // type, and Roborazzi holds the picture against the kept one. `-Pspecimens=record` keeps new pictures.        unitTests.isIncludeAndroidResources = true        unitTests.all { test ->            val record = (project.findProperty("specimens") as String?) == "record"            test.systemProperty("roborazzi.test.record", record.toString())            test.systemProperty("roborazzi.test.verify", (!record).toString())            test.systemProperty("robolectric.graphicsMode", "NATIVE")            test.systemProperty("robolectric.pixelCopyRenderMode", "hardware")            test.inputs.dir(specimens).withPropertyName("specimens")            test.maxHeapSize = "3g"        }    }    sourceSets["test"].assets.srcDir(specimenAssets)    defaultConfig { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" }    // The ink's letter model, one file for every app (`ink/InkModel`): the repo's assets/ink, beside nothing else.    // Its parity test reads the core's goldens as encoded (crates/cotton-core/tests/fixtures/ink/model-inputs.json).    sourceSets["main"].assets.srcDir(rootDir.resolve("../../assets/ink"))    sourceSets["androidTest"].assets.srcDir(rootDir.resolve("../../crates/cotton-core/tests/fixtures/ink"))    androidResources { noCompress += "tflite" }}kotlin {    compilerOptions { jvmTarget.set(JvmTarget.JVM_17) }}dependencies {    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")    api(platform("androidx.compose:compose-bom:2026.06.01"))    api("androidx.compose.ui:ui")    api("androidx.compose.foundation:foundation")    api("androidx.compose.material3:material3")    api("androidx.activity:activity-compose:1.12.4")    api("androidx.core:core-ktx:1.17.0")    // The launch screen (ShellActivity): the SplashScreen API on Android 12+, its compat path below.    api("androidx.core:core-splashscreen:1.2.0")    api("androidx.browser:browser:1.9.0")    api("androidx.fragment:fragment-ktx:1.8.9")    api("androidx.biometric:biometric:1.1.0")    api("androidx.lifecycle:lifecycle-process:2.9.2")    api("androidx.lifecycle:lifecycle-runtime-compose:2.9.2")    api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")    api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")    // The one audio player every app that plays sound shares (player/: Music, then Podcasts): ExoPlayer under a    // media session, the lock screen's, the notification's and the headset's controls.    api("androidx.media3:media3-exoplayer:1.8.0")    api("androidx.media3:media3-session:1.8.0")    // Transfers that outlive the process (Transfers.kt: Keep on phone's songs, episodes, books and whole films) and    // the periodic pass that catches the phone up with its object while the app is closed.    api("androidx.work:work-runtime-ktx:2.10.1")    // The vault's platform key, kept in the phone's own synced key store (core/BlockStore.kt, R7a), and the Credential    // Manager, which Cotton Keys' credential provider answers through (app/src/keys/.../provider).    api("com.google.android.gms:play-services-auth-blockstore:16.4.0")    api("androidx.credentials:credentials:1.5.0")    api("androidx.credentials:credentials-play-services-auth:1.5.0")    // Getting in (assets/design/shared/GETTING-IN.md): Approve scans the new device's square code with Google's code    // scanner, which draws its own camera page and needs no camera permission; the string goes to the core untouched.    api("com.google.android.gms:play-services-code-scanner:16.1.0")    // The ink's letter model (LiteRT, TFLite's runtime): the Interpreter API, the same weights as the iPhone's Core ML.    implementation("com.google.ai.edge.litert:litert:1.4.2")    testImplementation("junit:junit:4.13.2")    androidTestImplementation("androidx.test:runner:1.6.2")    androidTestImplementation("androidx.test.ext:junit:1.2.1")    androidTestImplementation("junit:junit:4.13.2")    androidTestImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1")    // Sites' WebView profiles, proven on the phone's own WebView (WebProfilesTest); Comms ships the same library.    androidTestImplementation("androidx.webkit:webkit:1.14.0")    testImplementation("org.json:json:20240303")    testImplementation("org.robolectric:robolectric:4.16")    testImplementation("io.github.takahirom.roborazzi:roborazzi:1.50.0")    testImplementation("io.github.takahirom.roborazzi:roborazzi-compose:1.50.0")    testImplementation("androidx.compose.ui:ui-test-junit4")    debugImplementation("androidx.compose.ui:ui-test-manifest")}