apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        applicationId "online.magicbox.app"
        minSdkVersion 13//8主題太差
        targetSdkVersion 23
        versionCode 8
        versionName "1.8"
    }

    signingConfigs {
        debug {
            storeFile file("magicbox_debug.keystore")
            storePassword "123456"
            keyAlias "magicbox"
            keyPassword "123456"
        }
    }
    //sha1:16:40:30:CA:5E:89:E1:64:9C:27:AE:42:D4:E4:23:B6:52:66:C7:26


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

}


////transformClasses for gradle 1.4
//android.applicationVariants.all { variant ->
//    variant.dex.dependsOn << processWithJavassist //在执行dx命令之前将代码打入到class中
//}
//
//task('processWithJavassist') << {
//    println '-----------开始往class插入代码-----------------'
//
//    String classPath = project(':app').buildDir.absolutePath + '/intermediates/classes/debug'//项目编译class所在目录
//    String libPath = "$rootDir/transformClasses;$rootDir/transformClasses/buildLib" //AntilazyLoad.class所在目录
//    String ignore = "*.App;*.BuildConfig;online.magicbox.bugfix.*;online.magicbox.app.R.*;cn.jpush.*"
//    println classPath
//    println libPath
//    println ignore
//
//    javaexec {
//        classpath "$rootDir/transformClasses/transformClasses.jar"
//        main = 'cn.georgeyang.TransformClasses'
//        args classPath,libPath,ignore
//    }
//}






//gradle.taskGraph.beforeTask { Task task ->
//    println "beforeTask:" + task.name + "," + task.group + "," + task.getProject().name
//        if (task.name.equals("preBuild") && task.getProject().name.equals("app")) {
//            String rootPath = project.rootDir.absolutePath
//            String jarPath = rootPath + "/transformClasses/transformClasses.jar"
//            String classPath = project.buildDir.absolutePath + '/intermediates/classes/debug'//项目编译class所在目录
//            String libPath = rootPath + "/transformClasses;" +  rootPath+ "/transformClasses/androidClass" //AntilazyLoad.class及android.jar解压后的class所在目录
//            String ignore = "*.App;*.BuildConfig;online.magicbox.bugfix.*;online.magicbox.app.R.*;cn.jpush.*"
//            project.javaexec {
//                classpath jarPath
//                main = 'cn.georgeyang.TransformClasses'
//                args classPath,libPath,ignore
//            }
//    }
//}

dependencies {
    compile files('src/main/jniLibs/jpush-android-2.1.5.jar')
    compile files('src/main/jniLibs/AMap_Location_V2.2.0_20151222.jar')
}


//transformClasses for gradle 1.5+
apply plugin: CodeInsert
class CodeInsert implements Plugin<Project> {
    @Override
    void apply(Project project) {
        project.afterEvaluate {
            project.android.applicationVariants.each { variant ->
                def dexTaskName = "transformClassesWithDexFor${variant.name.capitalize()}"
                def dexTask = project.tasks.findByName(dexTaskName)
                if (dexTask) {
                    String rootPath = project.rootDir.absolutePath
                    String jarPath = rootPath + "/transformClasses/transformClasses.jar"
                    String classPath = project.buildDir.absolutePath + '/intermediates/classes/debug'//项目编译class所在目录
                    String libPath = rootPath + "/transformClasses;" +  rootPath+ "/transformClasses/androidClass" //AntilazyLoad.class所在目录
                    String ignore = "*.App;*.BuildConfig;online.magicbox.bugfix.*;online.magicbox.app.R.*;cn.jpush.*"
                    project.javaexec {
                        classpath jarPath
                        main = 'cn.georgeyang.TransformClasses'
                        args classPath,libPath,ignore
                    }

                }
            }
        }
    }
}