plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'com.google.devtools.ksp'
    id 'org.jetbrains.kotlin.android'
    id 'org.jetbrains.kotlin.plugin.compose' version "2.2.20"
    id 'org.jetbrains.kotlin.plugin.serialization' version "2.2.20"
}

// NO FREE
if (!project.hasProperty('free')) {
    // Firebase
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'com.google.firebase.crashlytics'
    apply plugin: 'com.google.firebase.firebase-perf'
}

android {
    compileSdk 36
    
    buildFeatures {
        buildConfig = true
    }

    defaultConfig {
        applicationId "net.xzos.upgradeall"
        minSdkVersion 23
        targetSdkVersion 34
        versionCode 105
        versionName "0.20-alpha.4"
        if (project.hasProperty('appVerName')) {
            versionName = "${versionName}_${appVerName}"
        }
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        ksp {
            arg("room.schemaLocation", "$projectDir/schemas")
            arg("room.incremental", "true")
        }
        vectorDrawables {
            useSupportLibrary true
        }
    }
    buildTypes {
        release {
            // minifyEnabled true
            // shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            manifestPlaceholders = [enableCrashReporting: "true", appName: "UpgradeAll"]
        }
        debug {
            minifyEnabled false
            manifestPlaceholders = [enableCrashReporting: "false", appName: "UpgradeAll-β"]
            applicationIdSuffix ".debug"
            packaging {
                jniLibs {
                    keepDebugSymbols += "**/*.so"
                }
            }
        }
    }
    android.applicationVariants.configureEach { variant ->
        variant.outputs.configureEach {
            if (variant.buildType.name == 'release') {
                outputFileName = "UpgradeAll_${versionName}.apk"
            }
            if (variant.buildType.name == 'debug') {
                outputFileName = "UpgradeAll_${versionName}-debug.apk"
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_19
        targetCompatibility JavaVersion.VERSION_19
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_19
        freeCompilerArgs = ["-Xopt-in=kotlin.RequiresOptIn", "-XXLanguage:+InlineClasses"]
    }

    buildFeatures {
        // 视图绑定
        dataBinding true
        viewBinding true
    }

    dependenciesInfo.includeInApk false
    lint {
        abortOnError true
        checkReleaseBuilds false
    }
    namespace 'net.xzos.upgradeall'

    packagingOptions {
        resources {
            pickFirsts += 'META-INF/DEPENDENCIES'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.7.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.preference:preference-ktx:1.2.1'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.3'
    implementation 'androidx.recyclerview:recyclerview:1.4.0'
    implementation "androidx.drawerlayout:drawerlayout:1.2.0"
    implementation 'androidx.viewpager2:viewpager2:1.1.0'

    implementation 'androidx.activity:activity-ktx:1.11.0'
    implementation 'androidx.fragment:fragment-ktx:1.8.9'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.9.4'
    implementation 'androidx.navigation:navigation-ui-ktx:2.9.4'

    // Kotlin
    implementation "androidx.core:core-ktx:$android_ktx_version"
    //noinspection DifferentStdlibGradleVersion
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.9.3'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.3'
    implementation 'androidx.activity:activity-compose:1.11.0'
    implementation 'androidx.compose.ui:ui-viewbinding:1.9.1'
    implementation platform('androidx.compose:compose-bom:2025.09.00')
    implementation 'androidx.compose.ui:ui:1.9.1'
    implementation 'androidx.compose.ui:ui-graphics:1.9.1'
    implementation 'androidx.compose.ui:ui-tooling-preview:1.9.1'
    implementation 'androidx.compose.material3:material3:1.3.2'
    androidTestImplementation platform('androidx.compose:compose-bom:2025.09.00')
    androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.9.1'

    implementation 'com.jakewharton.threetenabp:threetenabp:1.4.9'
    debugImplementation 'androidx.compose.ui:ui-tooling:1.9.1'
    debugImplementation 'androidx.compose.ui:ui-test-manifest:1.9.1'

    // WorkManager
    implementation "androidx.work:work-runtime-ktx:$work_version"

    // Localization
    implementation 'com.akexorcist:localization:1.2.11'

    // 数据处理
    implementation 'com.jonathanfinerty.once:once:1.3.1'

    // 图片加载
    implementation 'com.github.bumptech.glide:glide:5.0.4'
    ksp 'com.github.bumptech.glide:ksp:5.0.4'

    // 界面设计
    // Google MD 库
    implementation 'com.google.android.material:material:1.13.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.github.kobakei:MaterialFabSpeedDial:2.0.0'
    // svg 单个 path 颜色切换
    implementation 'com.github.devsideal:VectorChildFinder:1.0.0'
    implementation 'dev.rikka.rikkax.insets:insets:1.3.0'
    implementation 'dev.rikka.rikkax.layoutinflater:layoutinflater:1.3.0'

    //RecyclerView
    implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.11'

    // 日历
    implementation 'com.github.6tail:lunar-java:1.7.4'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.7.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
    androidTestImplementation 'androidx.test.ext:junit:1.3.0'
    androidTestImplementation 'androidx.arch.core:core-testing:2.2.0'
    androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2'
    androidTestImplementation 'androidx.room:room-testing:2.8.0'
    androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0'

    implementation project(':app-backup')
    implementation project(':core-android-utils')
    implementation project(':core')
    implementation project(':core-utils')
    implementation project(':core-downloader')
    implementation project(':core-installer')

    // NO FREE
    if (!project.hasProperty('free')) {
        // Firebase
        implementation 'com.google.firebase:firebase-perf:22.0.1'
        implementation 'com.google.firebase:firebase-analytics:23.0.0'
        implementation 'com.google.firebase:firebase-crashlytics:20.0.1'
    }
    //Protobuf
    implementation 'com.google.protobuf:protobuf-java:4.32.0'
}

// fix different protobuf versions of gplayapi and firebase
configurations.all {
    resolutionStrategy {
        force 'com.google.protobuf:protobuf-java:4.32.0'
    }
    exclude group: 'com.google.protobuf', module: 'protobuf-javalite'
    exclude group: 'com.google.firebase', module: 'protolite-well-known-types'
}
