ext.alwaysLib = true //虽然apply了cc-settings-2.gradle，但一直作为library编译，否则别的组件依赖此module时会报错
apply from: rootProject.file("cc-settings.gradle")
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'kotlin-kapt'
apply plugin: 'android-aspectjx'
android {
    compileSdkVersion rootProject.ext.android["compileSdkVersion"]

    defaultConfig {
        minSdkVersion rootProject.ext.android["minSdkVersion"]
        targetSdkVersion rootProject.ext.android["targetSdkVersion"]
        versionCode rootProject.ext.android["versionCode"]
        versionName rootProject.ext.android["versionName"]
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
        multiDexEnabled true
        //配置注解处理器
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
    }

    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        debug {
            buildConfigField "boolean", "LOG_DEBUG", rootProject.ext.buildType["debugLogDebug"]
            buildConfigField "boolean", "USE_CANARY", rootProject.ext.buildType["debugUseCanary"]
            minifyEnabled false
            proguardFiles 'proguard.cfg'
        }
        release {
            buildConfigField "boolean", "LOG_DEBUG", rootProject.ext.buildType["releaseLogDebug"]
            buildConfigField "boolean", "USE_CANARY", rootProject.ext.buildType["releaseUseCanary"]
            minifyEnabled false
            zipAlignEnabled false
            proguardFiles 'proguard.cfg'
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'src/main/aidl']
            resources.srcDirs = ['src/main/java']
            aidl.srcDirs = ['src/main/aidl']
            res.srcDirs = ['src/main/res']
            assets.srcDirs = ['src/main/assets']
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/javabase64-1.2.jar')
    implementation files('libs/sun.misc.BASE64Decoder.jar')
    api files('libs/jcifs-1.3.19.jar')
    api files('libs/nexgon5lib.jar')
    api files('libs/ecracalib.jar')
    if (project.ext.runAsApp) {
        annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
        debugImplementation rootProject.ext.dependencies["canary-debug"]
        releaseImplementation rootProject.ext.dependencies["canary-release"]
        testImplementation rootProject.ext.dependencies["canary-release"]
    } else {
        compileOnly rootProject.ext.dependencies["dagger2-compiler"]
        compileOnly rootProject.ext.dependencies["canary-debug"]
        compileOnly rootProject.ext.dependencies["canary-release"]
        compileOnly rootProject.ext.dependencies["canary-release"]
    }
    api rootProject.ext.dependencies["viewpager2"]
    implementation files('libs\\ecracalib.jar')
    testImplementation rootProject.ext.dependencies["junit"]
    debugImplementation rootProject.ext.dependencies["canary-debug"]
    releaseImplementation rootProject.ext.dependencies["canary-release"]
    testImplementation rootProject.ext.dependencies["canary-release"]
    kapt rootProject.ext.dependencies["dagger2-compiler"]
    kapt rootProject.ext.dependencies["butterknife-compiler"]
    api rootProject.ext.dependencies["BaseRecyclerViewAdapter"]
    implementation rootProject.ext.dependencies["fastjson"]
    implementation rootProject.ext.dependencies["progressmanager"]
    implementation rootProject.ext.dependencies["autosize"]
    // test
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.gcssloop.recyclerview:pagerlayoutmanager:2.3.8'
    //商米打印庫
    api 'com.sunmi:printerlibrary:1.0.7'
    //扫码
    api 'com.github.bingoogolapple.BGAQRCode-Android:zxing:1.3.8'
    // loadingView
    api rootProject.ext.dependencies["loadingIndicatorView"]
    //加载反馈页管理
    api rootProject.ext.dependencies["loadsir"]
    //rxjava,rxbinding相關工具類
    api 'com.github.xuexiangjys:RxUtil2:1.1.5'
    //滴滴開源 哆啦A夢:辅助开发工具、测试效率工具、视觉辅助工具
    debugImplementation 'com.didichuxing.doraemonkit:dokitx:3.3.3'
    releaseImplementation 'com.didichuxing.doraemonkit:dokitx-no-op:3.3.3'
    //美團金剛狼日誌框架
    implementation rootProject.ext.dependencies['logan']
    //上下拉刷新
    api 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
    //时间选择器
    api rootProject.ext.dependencies["pickerview"]

//    implementation 'com.github.gzu-liyujiang:Android_CN_OAID:版本号'
    // 用于生成Java文件的库
//    implementation 'com.squareup:javapoet:1.13.0'
//    implementation 'com.google.auto.service:auto-service:1.0-rc6'
//    annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'

    api rootProject.ext.dependencies["permissionx"]
    api rootProject.ext.dependencies["design"]
    api rootProject.ext.dependencies["appcompat-v7"]

    api 'cn.bingoogolapple:bga-photopicker:2.0.2@aar'
    api 'cn.bingoogolapple:bga-flowlayout:1.0.0@aar'
    api 'cn.bingoogolapple:bga-baseadapter:2.0.0@aar'
    api 'pub.devrel:easypermissions:0.4.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    implementation 'cn.onestravel.one:one_bottom_navigationbar:1.1.1'

    api 'androidx.core:core-ktx:+'
    api 'com.github.huangyanbin:SmartTable:2.2.0'
    implementation 'com.lxj:xpopup:2.2.10'
    implementation "androidx.documentfile:documentfile:1.0.1"
//    implementation 'com.github.markzhai:blockcanary-android:1.5.0'
    implementation 'org.aspectj:aspectjrt:1.8.14'
    aspectjx {
        exclude 'androidx', 'org.jetbrains.kotlin', "module-info", 'com.google', 'com.squareup', 'org.apache', 'versions.9', 'com.squareup.okio', 'okio', 'leakcanary', 'com.google.firebase', 'com.google.android'
    }
}
repositories {
    mavenCentral()
}
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main

final def log = project.logger
android.libraryVariants.all { variant ->
    if (!variant.buildType.isDebuggable()) {
        log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.")
        return
    }

    JavaCompile javaCompile = variant.javaCompiler
    javaCompile.doLast {
        String[] args = ["-showWeaveInfo",
                         "-1.8",
                         "-inpath", javaCompile.destinationDir.toString(),
                         "-aspectpath", javaCompile.classpath.asPath,
                         "-d", javaCompile.destinationDir.toString(),
                         "-classpath", javaCompile.classpath.asPath,
                         "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)]
        log.debug "ajc args: " + Arrays.toString(args)

        MessageHandler handler = new MessageHandler(true)
        new Main().run(args, handler)
        for (IMessage message : handler.getMessages(null, true)) {
            switch (message.getKind()) {
                case IMessage.ABORT:
                case IMessage.ERROR:
                case IMessage.FAIL:
                    log.error message.message, message.thrown
                    break
                case IMessage.WARNING:
                    log.warn message.message, message.thrown
                    break
                case IMessage.INFO:
                    log.info message.message, message.thrown
                    break
                case IMessage.DEBUG:
                    log.debug message.message, message.thrown
                    break
            }
        }
    }
}
