apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 26
    }

    sourceSets {
        main {
            java.srcDirs += ['src/main/apacheCommonsLang']
        }
    }

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

// Make sure that hiddenapistubs are placed before the Android SDK in xposed-bridge.iml
// as there doesn't seem to be any way to configure this in Android Studio.
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
    }
}

dependencies {
    compileOnly project(':hiddenapi-stubs')
    compileOnly project(':dexmaker')
}

afterEvaluate {

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

}