plugins {
    id 'com.android.application'
}

boolean keyStoreDefined = project.hasProperty('signingStoreLocation') &&
        project.hasProperty('signingStorePassword') &&
        project.hasProperty('signingKeyAlias') &&
        project.hasProperty('signingKeyPassword')

repositories {
    maven {
        url 'https://jitpack.io'
    }
}

android {
    compileSdk 34
    ndkVersion '27.2.12479018'
    namespace 'org.adaway'

    defaultConfig {
        minSdk 26
        targetSdk 33
        versionCode libs.versions.appCode.get() as int
        versionName libs.versions.appName.get()

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [
                        "room.schemaLocation": "$projectDir/schemas".toString(),
                        "room.incremental"   : "true"
                ]
            }
        }

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    /*
     * To sign release build, create file gradle.properties in ~/.gradle/ with this content:
     *
     * signingStoreLocation=/home/key.store
     * signingStorePassword=xxx
     * signingKeyAlias=alias
     * signingKeyPassword=xxx
     */
    if (keyStoreDefined) {
        println "Found signature properties in gradle.properties. Build will be signed."

        signingConfigs {
            release {
                storeFile file(signingStoreLocation)
                storePassword signingStorePassword
                keyAlias signingKeyAlias
                keyPassword signingKeyPassword
            }
        }

        buildTypes.debug.signingConfig = signingConfigs.release
        buildTypes.release.signingConfig = signingConfigs.release
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    buildFeatures {
        viewBinding true
    }

    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
    }

    buildTypes {
//        debug {
//            shrinkResources false
//            minifyEnabled false
//            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    // Do not abort build if lint finds errors
    lint {
        disable 'MissingTranslation'
    }
}

dependencies {
    // Native modules
    implementation project(':tcpdump')
    implementation project(':webserver')

    // AndroidX components
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.fragment:fragment:1.8.1'
    // "fragment-ktx" is not used but was added to fix the following dependency error:
    // Duplicate class androidx.lifecycle.ViewModelLazy found in modules lifecycle-viewmodel-2.5.0-runtime (androidx.lifecycle:lifecycle-viewmodel:2.5.0) and lifecycle-viewmodel-ktx-2.3.1-runtime
    implementation 'androidx.fragment:fragment-ktx:1.8.1'
    implementation 'androidx.paging:paging-runtime:3.3.0'
    implementation 'androidx.preference:preference:1.2.1'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.room:room-runtime:2.6.1'
    implementation 'androidx.room:room-paging:2.6.1'
    annotationProcessor 'androidx.room:room-compiler:2.6.1'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'androidx.work:work-runtime:2.8.1'
    implementation 'com.google.android.material:material:1.9.0'

    // Collections related
    implementation libs.guava
    // Network related
    implementation libs.okhttp3.okhttp
    // Logging related
    implementation libs.timber
    if (keyStoreDefined) {
        implementation project(':sentrystub')
    } else {
        implementation platform('io.sentry:sentry-bom:7.8.0')
        implementation('io.sentry:sentry-android')
        implementation('io.sentry:sentry-android-fragment')
        implementation('io.sentry:sentry-android-timber')
    }

    // Root related
    implementation libs.libsu

    // VPN related
    implementation libs.bundles.pcap4j
    implementation libs.dnsjava
    implementation libs.slf4j.android
    implementation libs.okhttp.dnsoverhttps

    // Test related
    testImplementation libs.junit
    testImplementation libs.json
    androidTestImplementation libs.bundles.androidx.test
    androidTestImplementation libs.junit
}
