apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
//apply plugin: 'com.jaredsburrows.license'

Properties properties = new Properties()
InputStream inputStream = project.getParent().file('core.properties').newDataInputStream();
properties.load(inputStream)

def version = '1.0.0'
def version_code = 2022110201
android {
    compileSdkVersion rootProject.ext.compile_sdk_version

    defaultConfig {
        applicationId properties.getProperty("CORE_PACKAGENAME")
        minSdkVersion rootProject.ext.min_sdk_version
        //noinspection ExpiredTargetSdkVersion
        targetSdkVersion 23
        versionCode version_code
        versionName version
        multiDexEnabled true
        buildConfigField 'String', 'VA_VERSION_NAME', '"V' + version + '"'
        buildConfigField "String", "BUGLY_ID", "\"" + properties.getProperty("BUGLY_ID") + "\""
        buildConfigField "String", "SECSPACE_PACKAGENAME", "\"" + properties.getProperty("SECSPACE_PACKAGENAME") + "\""
        buildConfigField "String", "PACKAGENAME_32", "\"" + properties.getProperty("CORE_PACKAGENAME") + "\""
        buildConfigField "String", "PACKAGENAME_64", "\"" + properties.getProperty("CORE_PACKAGENAME_64") + "\""
        manifestPlaceholders = [
                CORE_PACKAGENAME   : properties.getProperty("CORE_PACKAGENAME"),
                CORE_PACKAGENAME_64: properties.getProperty("CORE_PACKAGENAME_64"),
                VA_VERSION         : '' + version_code,
        ]
        ndk {
            //abiFilters 'armeabi-v7a'
            abiFilters 'armeabi-v7a'
        }
    }
    sourceSets {
        main {
            if (!Boolean.parseBoolean(buildSandboxSo)) {
                jniLibs.srcDirs = ['libs', 'libso']
                jni.srcDirs = []
            } else {
                jniLibs.srcDirs = ['libs']
            }
            if (Boolean.parseBoolean(IS_EVALUATION)) {
                manifest.srcFile 'src/main/evaluation/AndroidManifest.xml'
            } else {
                manifest.srcFile 'src/main/AndroidManifest.xml'
            }
        }
    }

    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    publishNonDefault true


    signingConfigs {
        String keyAliasValue = keyAlias
        String keyPasswordValue = keyPassword
        File keystoreFile = null
        String keystorePasswordValue = keystorePassword

        if (keyPasswordValue.length() == 0) {
            keyPasswordValue = System.getenv("keystore_password") ?: "wrong_password"
            println("get keyPassword from env.")
        } else {
            println("get keyPassword from properties.")
        }

        if (keystorePasswordValue.length() == 0) {
            keystorePasswordValue = keyPasswordValue
            println("keystorePasswordValue is empty, use keyPasswordValue")
        }

        if (keystorePath.length() == 0) {
            String keystorePathFromEnv = System.getenv("keystore_file") ?: " wrong_keystore"
            keystoreFile = file(keystorePathFromEnv)
            println("get keystorePath from env: " + keystoreFile)
        } else {
            println("get keystorePath from properties: " + keystorePath)
            keystoreFile = new File(getRootDir(), keystorePath)
        }

        release_config {
            keyAlias keyAliasValue
            keyPassword keyPasswordValue
            storeFile keystoreFile
            storePassword keystorePasswordValue
            v1SigningEnabled true
            v2SigningEnabled false
        }
    }
    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            zipAlignEnabled false
            signingConfig signingConfigs.release_config
            if (isWindows()) {
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro',
                        '..\\proguards\\proguard_base.pro', '..\\proguards\\proguard_third.pro',
                        '..\\proguards\\proguard_lib.pro', '..\\proguards\\proguard_lib_hook.pro'
            } else {
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro',
                        '../proguards/proguard_base.pro', '../proguards/proguard_third.pro',
                        '../proguards/proguard_lib.pro', '../proguards/proguard_lib_hook.pro'
            }
        }

        release {
            debuggable false
            minifyEnabled true
            zipAlignEnabled true
            if (isWindows()) {
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro',
                        '..\\proguards\\proguard_base.pro', '..\\proguards\\proguard_third.pro',
                        '..\\proguards\\proguard_lib.pro', '..\\proguards\\proguard_lib_hook.pro'
            } else {
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro',
                        '../proguards/proguard_base.pro', '../proguards/proguard_third.pro',
                        '../proguards/proguard_lib.pro', '../proguards/proguard_lib_hook.pro'
            }
            signingConfig signingConfigs.release_config
        }
    }
    externalNativeBuild {
        ndkBuild {
            if (Boolean.parseBoolean(buildSandboxSo)) {
                path file("src/main/jni/Android.mk")
            }
        }
    }

    lintOptions {
        //IJobService need NewApi
        abortOnError false
        warning 'NewApi', 'OnClick', 'EllipsizeMaxLines'
    }

}

repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'org.aspectj:aspectjrt:1.8.9'
    implementation 'androidx.annotation:annotation:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.appcompat:appcompat:$appcompat_version"
    implementation "com.google.android.material:material:$arch_material_version"
    implementation 'com.jakewharton.android.repackaged:dalvik-dx:9.0.0_r3'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "com.google.code.gson:gson:$gson_version"
    implementation "me.weishu:free_reflection:3.0.1"
    implementation "com.tencent:mmkv-static:$mmkv_version"
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    kapt "com.android.databinding:compiler:3.5.3"
    implementation 'com.tencent.bugly:crashreport:latest.release'

    implementation project(path: ':lib_api')
    implementation project(path: ':lib_permission_guide')
    implementation(name: 'xposedcompat', ext: 'aar')
    implementation(name: 'mdmonline', ext: 'aar')
    implementation(name: 'secspace', ext: 'aar')

}

//licenseReport {
//    generateCsvReport = false
//    generateHtmlReport = true
//    generateJsonReport = false
//    generateTextReport = false
//    //ignoredPatterns = []
//    // These options are ignored for Java projects
//    copyCsvReportToAssets = false
//    copyHtmlReportToAssets = false
//    copyJsonReportToAssets = false
//    copyTextReportToAssets = false
//    //useVariantSpecificAssetDirs = false
//}
