apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"

android {
    namespace = "{{PACKAGE_NAME}}"
    compileSdk = 34
    ndkVersion "26.1.10909125"
    def repoRoot = rootProject.projectDir.parentFile
    def benchSpecDir = new File(repoRoot, "target/mobile-spec/android")
    def generatedMainBenchSpec = new File(projectDir, "src/main/assets/bench_spec.json")
    if (!benchSpecDir.exists()) {
        benchSpecDir.mkdirs()
    }

    defaultConfig {
        applicationId "{{PACKAGE_NAME}}"
        minSdk 24
        targetSdk 34
        versionCode 1
        versionName "1.0.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testBuildType project.findProperty("mobenchTestBuildType") ?: "debug"
    }

    buildTypes {
        debug {
            minifyEnabled false
        }
        release {
            minifyEnabled false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }

    sourceSets {
        main {
            jniLibs.srcDirs "src/main/jniLibs"
            if (!generatedMainBenchSpec.exists()) {
                assets.srcDirs += [benchSpecDir.absolutePath]
            }
        }
        androidTest {
            if (!generatedMainBenchSpec.exists()) {
                assets.srcDirs += [benchSpecDir.absolutePath]
            }
        }
    }

    packagingOptions {
        jniLibs {
            // Keep symbols in Rust shared objects; avoid strip warning.
            keepDebugSymbols += ["**/lib{{LIBRARY_NAME}}.so"]
        }
    }
}

dependencies {
    implementation "androidx.core:core-ktx:1.12.0"
    implementation "androidx.appcompat:appcompat:1.6.1"
    implementation "com.google.android.material:material:1.11.0"
    implementation "net.java.dev.jna:jna:5.14.0@aar"
    androidTestImplementation "androidx.test.ext:junit:1.1.5"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
}
