import groovy.json.JsonSlurper

def computeVersionName() {
    // dynamically retrieve version from package.json
    def slurper = new JsonSlurper()
    def json = slurper.parse(file('../package.json'), "utf-8")
    return json.version
}
def checkEnvrionment(){
    if (!System.properties["PackageName"]) {
        throw new Exception("请在主应用的文件里配置 packageName")
    }

    if (!System.properties["HWAppId"]) {
        throw new Exception("请在主应用的文件里配置 HWAppId")
    }

    if (!System.properties["MIAppId"]) {
        throw new Exception("请在主应用的文件里配置 MIAppId")
    }

    if (!System.properties["MIAppKey"]){
        throw new Exception("请在主应用的文件里配置 MIAppKey")
    }
}

buildscript {
    repositories {
        google()
        jcenter()
        maven:'http://developer.huawei.com/repo/'
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }

    
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    buildToolsVersion "28.0.3"

    defaultConfig {
        checkEnvrionment()

        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        // get version name from package.json version
        versionName computeVersionName()
        manifestPlaceholders = [
                PACKAGE_NAME: System.properties["PackageName"],//包名
                HW_APPID : System.properties["HWAppId"] ,  // HUA Wei AppID
                MI_APPID: System.properties["MIAppId"] ,// 小米APPID
                MI_APPKEY: System.properties["MIAppKey"] // 小米Key
        ]
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.facebook.react:react-native:0.20.+'

    implementation 'com.hjq:xxpermissions:5.2'
    // compile 'com.huawei.android.hms:push:2.6.1.301'
}
