group = 'com.taobao.android.atlasdemo'
version = getEnvValue("versionName", "1.0.0");
def apVersion = getEnvValue("apVersion", "");

apply plugin: 'com.android.application'
apply plugin: 'com.taobao.atlas'
//apply plugin: 'com.taobao.atlas.dexpatch'

//通过增加判断逻辑，打出不同类型的定制包
def appId = "com.taobao.demo"
def minVersion = 14
if (project.hasProperty("beta")) {
	appId = "com.taobao.atlas.beta"
	minVersion = 21
}

repositories {
    mavenLocal()
    jcenter()
}

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId appId
        minSdkVersion minVersion
        targetSdkVersion 26
        versionCode 1
        versionName version
        vectorDrawables.useSupportLibrary = true
        //通过增加判断逻辑，打出不同类型的定制包
        if (project.hasProperty("beta")) {
            buildConfigField "boolean", "API_ENV", "false"
        }else{
        	buildConfigField "boolean", "API_ENV", "false"
        }
        multiDexEnabled = false

    }
        
    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }


    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            ndk {
                abiFilters "x86","armeabi"
            }

        }
    }

}

atlas {
    instantAppEnabled true
    atlasEnabled true
    tBuildConfig {
        preLaunch = 'com.taobao.demo.DemoPreLaunch'
        classInject false
        aaptConstantId true
        dataBindingBundles = ['com.taobao.databindbundle']
       allBundlesToMdex true

    }

   

    patchConfigs {
        debug {
            createTPatch false
        }
    }


    buildTypes {
        debug {
            if (apVersion) {
                baseApDependency "com.taobao.android.atlasdemo:AP-debug:${apVersion}@ap"
                patchConfig patchConfigs.debug
            }
        }
    }
}


dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile project(':middlewarelibrary')
    compile project(':splashscreen')
    compile project(':databindinglibrary')
//    compile project(':activitygroupcompat')
    bundleCompile project(':firstbundle')
    bundleCompile project(':secondbundle')
    bundleCompile project(':remotebundle')
    bundleCompile project(':publicbundle')
    bundleCompile project(':databindbundle')
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:support-vector-drawable:25.1.0'
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.alibaba:fastjson:1.1.45.android@jar'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:25.3.0'
    compile project(':atlas_core')
}

String getEnvValue(key, defValue) {
    def val = System.getProperty(key);
    if (null != val) {
        return val;
    }
    val = System.getenv(key);
    if (null != val) {
        return val;
    }
    return defValue;
}

tasks.whenTaskAdded { task ->
    if (task.name.contains("DebugAndroidTest")) {
        task.setEnabled(false);
    }
    if (task.name.contains("assemble")) {
        def files = null;
        def file = new File(task.project.getBuildDir(), "outputs");
        if (file.exists() && new File(file, "tpatch-debug").exists()) {
            files = new File(file, "tpatch-debug").listFiles();
        }
        if (files != null) {
            for (File file1 : files) {
                if (file1.getName().endsWith(".json") || file1.getName().endsWith(".tpatch")) {

                    if (!new File(task.project.getRootDir(), "hisTpatch").exists()) {
                        new File(task.project.getRootDir(), "hisTpatch").mkdirs();
                    }
                    org.apache.commons.io.FileUtils.copyFileToDirectory(file1, new File(task.project.getRootDir(), "hisTpatch"));
                }
            }
        }
    }
}

apply plugin: 'maven'
apply plugin: 'maven-publish'

publishing {
    repositories {
        mavenLocal()
    }
}

publishing {
    publications {
        maven(MavenPublication) {
            artifact "${project.buildDir}/outputs/apk/debug/${project.name}-debug.ap"
            artifactId "AP-debug"
        }
    }
}
