~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
143 lines · 5.5 KB Raw History
// HUDKit for Android: HUD's renderer in Jetpack Compose, drawing the views the
// server resolves (`_meta.ui` trees) as web/renderer and ios/HUDKit draw them,
// and what the app needs to call HUD's tools. The app (`:app`) is a thin host.
// Published as `place.hud:hudkit` (docs/sdk.md): its release AAR, with its
// sources, a POM and Gradle's module metadata naming what it depends on.
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    alias(libs.plugins.android.library)
    alias(libs.plugins.kotlin.compose)
    alias(libs.plugins.kotlin.serialization)
    `maven-publish`
}

group = "place.hud"
// HUD's one version (knope.toml), which `knope release` keeps here.
version = providers.gradleProperty("hudVersion").get()

android {
    namespace = "place.hud.kit"
    compileSdk = 37

    defaultConfig {
        minSdk = 28
        consumerProguardFiles("consumer-rules.pro")
        // The version kits say on every call (`Kit.VERSION`), the one above.
        buildConfigField("String", "HUD_VERSION", "\"${project.version}\"")
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    buildFeatures {
        compose = true
        buildConfig = true
    }

    testOptions {
        unitTests {
            isReturnDefaultValues = true
            isIncludeAndroidResources = true
            // The tests read the answers iOS's tests read: one fixture for both ports; and
            // the JSON Schemas of a view and an app file, for the icons the catalog allows.
            all {
                it.systemProperty("hud.fixtures", rootProject.file("../ios/HUDKit/Tests/HUDKitTests/Fixtures").path)
                it.systemProperty("hud.schemas", rootProject.file("../schemas/json").path)
            }
        }
    }

    publishing {
        singleVariant("release") {
            withSourcesJar()
        }
    }
}

kotlin {
    compilerOptions {
        jvmTarget.set(JvmTarget.JVM_17)
    }
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.compose)
    implementation(libs.androidx.activity.compose)

    api(platform(libs.androidx.compose.bom))
    api(libs.androidx.ui)
    api(libs.androidx.foundation)
    api(libs.androidx.material3)
    // The ~50 icons of the core set, for the controls the web's icons have none of (chevrons, a player's transport).
    implementation(libs.androidx.material.icons.core)
    implementation(libs.androidx.ui.tooling.preview)
    debugImplementation(libs.androidx.ui.tooling)

    api(libs.kotlinx.serialization.json)
    implementation(libs.kotlinx.coroutines.android)
    // `Http.client` is the app's too: one pool of connections for HUD's calls and its own.
    api(libs.okhttp)
    // Signing in in a Custom Tab (WebSignIn), as iOS's ASWebAuthenticationSession.
    implementation(libs.androidx.browser)
    implementation(libs.coil.compose)
    implementation(libs.coil.network.okhttp)
    implementation(libs.androidx.exifinterface)
    implementation(libs.androidx.media3.exoplayer)
    implementation(libs.androidx.media3.exoplayer.hls)
    implementation(libs.androidx.media3.ui.compose)
    // MapLibre, drawing a `Map` over the Protomaps basemap of OpenStreetMap's
    // data the web draws, from tiles.grain.social (src/main/assets/basemap):
    // MapLibre Native's OpenGL ES build in place of the Vulkan one
    // maplibre-compose brings, for every app on HUDKit, as its POM and module
    // metadata say. The Vulkan backend aborts on the emulator's Vulkan
    // (gfxstream), and its manifest requires Vulkan 1.0, which hides an app
    // from devices without it.
    implementation(libs.maplibre.compose) {
        exclude(group = "org.maplibre.gl", module = "android-sdk")
    }
    implementation(libs.maplibre.native.opengl)

    testImplementation(libs.junit)
    testImplementation(libs.kotlinx.coroutines.test)
    testImplementation(libs.robolectric)
    testImplementation(libs.mockwebserver)
    testImplementation(libs.androidx.test.core)
    testImplementation(libs.androidx.ui.test.junit4)
    testImplementation(libs.androidx.ui.test.manifest)
}

// `./gradlew :hudkit:publish` sends the release to HUD's Maven repository on
// knotless (HUD_MAVEN_URL overrides it), as the account HUD_MAVEN_USERNAME
// names, with HUD_MAVEN_PASSWORD, an app password of theirs (release.yml);
// `publishToMavenLocal` puts it in ~/.m2 to try it in an app.
publishing {
    publications {
        register<MavenPublication>("release") {
            artifactId = "hudkit"
            afterEvaluate { from(components["release"]) }
            pom {
                name.set("HUDKit")
                description.set("HUD's renderer in Jetpack Compose: the views HUD's server resolves, drawn natively, and the client that calls its tools.")
                url.set("https://knotless.dev/chadtmiller.com/hud")
                licenses {
                    license { name.set("MIT"); url.set("https://opensource.org/license/mit") }
                    license { name.set("Apache-2.0"); url.set("https://www.apache.org/licenses/LICENSE-2.0") }
                }
            }
        }
    }
    repositories {
        maven {
            name = "hud"
            url = uri(providers.environmentVariable("HUD_MAVEN_URL").getOrElse("https://knotless.dev/maven/did:plc:bcgltzqazw5tb6k2g3ttenbj/3n2kdckpvmnlo/"))
            credentials {
                username = providers.environmentVariable("HUD_MAVEN_USERNAME").orNull
                password = providers.environmentVariable("HUD_MAVEN_PASSWORD").orNull
            }
        }
    }
}