apply plugin: 'com.android.library'

android {
    compileSdkVersion androidCompileSdkVersion.toInteger()

    defaultConfig {
        minSdkVersion androidMinSdkVersion.toInteger()
        targetSdkVersion androidTargetSdkVersion.toInteger()
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            buildConfigField("String", "VERSION_NAME", "\"${rootProject.ext.versionName}\"")
            buildConfigField("Integer", "VERSION_CODE", String.valueOf(rootProject.ext.versionCode))
        }
        debug {
            buildConfigField("String", "VERSION_NAME", "\"${rootProject.ext.versionName}\"")
            buildConfigField("Integer", "VERSION_CODE", String.valueOf(rootProject.ext.versionCode))
        }
    }

    ndkVersion androidCompileNdkVersion
}

dependencies {
    compileOnly project(':hiddenapi-stubs')
    api project(':xposed-bridge')
    compileOnly project(':dexmaker')
    compileOnly 'com.android.support:support-annotations:28.0.0'
}


preBuild.doLast {
    def imlFile = file(project.name + ".iml")
    try {
        def parsedXml = (new groovy.util.XmlParser()).parse(imlFile)
        def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
        parsedXml.component[1].remove(jdkNode)
        def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
        new groovy.util.Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
        groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
    } catch (FileNotFoundException e) {
        // nop, iml not found
    }
}

afterEvaluate {

    tasks.withType(JavaCompile) {
        options.compilerArgs.add("-Xbootclasspath/p:${hiddenApiStubJarFilePath}")
    }

    task("copyCommonProperties", type: Copy) {
        from file("${projectDir}/template_override/")
        into file(templateRootPath)
    }
}