plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

// Release signing is configured only if a local keystore.properties exists
// (gitignored). Otherwise the release build is unsigned, which is what F-Droid
// and reproducible-build verification want.
def keystoreProps = rootProject.file('keystore.properties')

android {
    namespace 'invalid.lena.rsend'
    compileSdk 35

    defaultConfig {
        applicationId 'invalid.lena.rsend'
        minSdk 30
        targetSdk 35
        versionCode 1
        versionName '0.1.0'
        // Ship only the ABIs we build native libs for.
        ndk { abiFilters 'arm64-v8a', 'x86_64' }
    }

    signingConfigs {
        if (keystoreProps.exists()) {
            def props = new Properties()
            keystoreProps.withInputStream { props.load(it) }
            release {
                storeFile rootProject.file(props['storeFile'])
                storePassword props['storePassword']
                keyAlias props['keyAlias']
                keyPassword props['keyPassword']
                // Include v1 (JAR) signing too; some sideload installers
                // (Samsung One UI on Android 11/12) reject v2-only APKs with
                // "problem parsing the package".
                enableV1Signing true
                enableV2Signing true
                enableV3Signing true
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            if (keystoreProps.exists()) {
                signingConfig signingConfigs.release
            }
        }
    }

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

    buildFeatures {
        buildConfig true
    }

    // Native executables ship as lib*.so and must be extracted so we can exec
    // them from nativeLibraryDir (useLegacyPackaging => extractNativeLibs=true).
    packaging {
        jniLibs {
            useLegacyPackaging true
        }
    }

    // Reproducible / F-Droid: do not embed the Google dependency metadata block.
    dependenciesInfo {
        includeInApk false
        includeInBundle false
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.13.1'
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'androidx.work:work-runtime-ktx:2.10.0'

    // The real org.json shadows the android.jar stub so JSON tests run on the JVM.
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.json:json:20240303'
}
