// Android Gradle project for peat-mesh's functional sync test.
//
// Until M4b (peat-mesh#138), this project also cross-compiled a test-
// only JNI shim under ./jni/. M4b retired that shim and switched the
// instrumented tests to peat-ffi's production JNI surface, pulled in
// as a Maven Central AAR. The .so + Kotlin extern declarations are
// now part of `com.defenseunicorns:peat-ffi:<version>`, so this file
// no longer cargo-builds anything.
//
// The instrumented tests still ship from this project because they
// remain peat-mesh's regression gate for sync-protocol behavior
// (#134, #136). They just delegate the JNI plumbing upstream.

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
}

android {
    namespace = "com.defenseunicorns.peat_mesh.test"
    compileSdk = 34

    defaultConfig {
        minSdk = 26
        targetSdk = 34
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        ndk {
            // Match the device on the self-hosted runner (Galaxy Tab
            // A9+ arm64). For dev on an x86_64 emulator override with
            // `-PandroidTestAbis=x86_64` or `ANDROID_TEST_ABIS=x86_64`.
            val abis = (findProperty("androidTestAbis") as? String
                ?: System.getenv("ANDROID_TEST_ABIS")
                ?: "arm64-v8a")
                .split(",")
                .map { it.trim() }
            abiFilters += abis
        }
    }

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

    kotlinOptions {
        jvmTarget = "17"
    }

    sourceSets {
        getByName("main") {
            java.srcDir("src/main/kotlin")
        }
        getByName("androidTest") {
            java.srcDir("src/androidTest/kotlin")
        }
    }
}

// Repositories (google, mavenCentral) are declared at the settings
// level in settings.gradle.kts under
// `dependencyResolutionManagement { repositoriesMode = FAIL_ON_PROJECT_REPOS }`.
// Declaring them in this file would conflict with that mode — peat-ffi
// resolves via the settings-level mavenCentral entry without further
// configuration here.

dependencies {
    // 0.1.2 ships the canonical `PeatJni` / `PeerEventManager` Kotlin
    // sources inside the AAR (peat#886) plus the env.exception_clear()
    // fix that lets `System.loadLibrary("peat_ffi")` survive in
    // consumers without a custom `PeerEventManager` (peat#887), plus
    // the deterministic `forceStoreErrorForTestingJni` fault injector
    // that lets `getDocumentThrowsOnStoreError` fail-closed on the
    // throw contract (peat#885). The local PeatJni.kt + PeerEventManager.kt
    // stubs that previous releases needed are deleted on this bump.
    implementation("com.defenseunicorns:peat-ffi:0.1.2")

    androidTestImplementation("androidx.test.ext:junit:1.2.1")
    androidTestImplementation("androidx.test:runner:1.6.2")
}
