build.gradle 10.8 KB
apply plugin: 'com.android.application'
apply plugin: 'android-aspectjx'
apply from: '../common.gradle'

// Android 代码规范文档:https://github.com/getActivity/AndroidCodeStandard
android {
    sourceSets {
        main {
            // res 资源目录配置
            jniLibs.srcDirs = ['src/main/libs']
            res.srcDirs(
                    'src/main/res',
                    'src/main/res-sw',
            )
        }
    }
    // 资源目录存放指引:https://developer.android.google.cn/guide/topics/resources/providing-resources
    defaultConfig {

        // 无痛修改包名:https://www.jianshu.com/p/17327e191d2e
        applicationId 'com.studymachine.www'

        // 仅保留中文语种的资源
        resConfigs 'zh'

        // 仅保留 xxhdpi 图片资源(目前主流分辨率 1920 * 1080)
        resConfigs 'xxhdpi'

        // 混淆配置
        proguardFiles 'proguard-sdk.pro', 'proguard-app.pro'

        // 日志打印开关
        buildConfigField('boolean', 'LOG_ENABLE', '' + LOG_ENABLE + '')
        // 测试包下的 BuglyId
        buildConfigField('String', 'BUGLY_ID', '"' + BUGLY_ID + '"')
        // 测试服务器的主机地址
        buildConfigField('String', 'HOST_URL', '"' + HOST_URL + '"')
        // 测试oss服务器的主机地址
        buildConfigField('String', 'IMAGER_HOST_URL', '"' + IMAGER_HOST_URL + '"')
        // 测试web的主机地址
        buildConfigField('String', 'WEB_HOST_URL', '"' + WEB_HOST_URL + '"')


        javaCompileOptions {
            annotationProcessorOptions {
                // EventBus Apt 索引类生成位置
                arguments = [eventBusIndex: applicationId + '.MyEventBusIndex']
            }
        }
    }

    // Apk 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
    signingConfigs {
        config {
            storeFile file(StoreFile)
            storePassword StorePassword
            keyAlias KeyAlias
            keyPassword KeyPassword
            v1SigningEnabled true
            v2SigningEnabled true
        }
        release {
            storeFile file(StoreFile)
            storePassword StorePassword
            keyAlias KeyAlias
            keyPassword KeyPassword
            v1SigningEnabled true
            v2SigningEnabled false
        }
    }

    // 构建配置:https://developer.android.google.cn/studio/build/build-variants
    buildTypes {

        debug {
            // 给包名添加后缀
            applicationIdSuffix '.debug'
            // 调试模式开关
            debuggable true
            jniDebuggable true
            // 压缩对齐开关
            zipAlignEnabled false
            // 移除无用的资源
            shrinkResources false
            // 代码混淆开关
            minifyEnabled false
            // 签名信息配置
            signingConfig signingConfigs.config
            // 添加清单占位符
            addManifestPlaceholders([
                    'app_name': '未来猫 Debug 版'
            ])
            // 调试模式下只保留一种架构的 so 库,提升打包速度
            ndk {
                abiFilters 'armeabi-v7a'
            }
        }

        preview.initWith(debug)
        preview {
            applicationIdSuffix ''
            // 添加清单占位符
            addManifestPlaceholders([
                    'app_name': '@string/app_name'
            ])
        }

        release {
            // 调试模式开关
            debuggable false
            jniDebuggable false
            // 压缩对齐开关
            zipAlignEnabled true
            // 移除无用的资源
            shrinkResources true
            // 代码混淆开关
            minifyEnabled true
            // 签名信息配置
            signingConfig signingConfigs.release
            // 添加清单占位符
            addManifestPlaceholders([
                    'app_name': '@string/app_name'
            ])
            // 仅保留两种架构的 so 库,根据 Bugly 统计得出
            ndk {
                // armeabi:万金油架构平台(占用率:0%)
                // armeabi-v7a:曾经主流的架构平台(占用率:10%)
                // arm64-v8a:目前主流架构平台(占用率:95%)
                abiFilters 'armeabi-v7a'
//                , 'arm64-v8a' 因为swf的原因 不能保留
            }
        }
    }

    packagingOptions {
        // 剔除这个包下的所有文件(不会移除签名信息)
        exclude 'META-INF/*******'
    }

    // AOP 配置(exclude 和 include 二选一)
    // 需要进行配置,否则就会引发冲突,具体表现为:
    // 第一种:编译不过去,报错:java.util.zip.ZipException:Cause: zip file is empty
    // 第二种:编译能过去,但运行时报错:ClassNotFoundException: Didn't find class on path: DexPathList
    aspectjx {
        // 排除一些第三方库的包名(Gson、 LeakCanary 和 AOP 有冲突)
        // exclude 'androidx', 'com.google', 'com.squareup', 'org.apache', 'com.alipay', 'com.taobao', 'versions.9'
        // 只对以下包名做 AOP 处理
        include android.defaultConfig.applicationId
    }

    applicationVariants.all { variant ->
        // apk 输出文件名配置
        variant.outputs.all { output ->
            outputFileName = rootProject.getName() + '_v' + variant.versionName + '_' + variant.buildType.name
            if (variant.buildType.name == buildTypes.release.getName()) {
                outputFileName += '_' + new Date().format('MMdd')
            }
            outputFileName += '.apk'
        }
    }
}

// 添加构建依赖项:https://developer.android.google.cn/studio/build/dependencies
// api 与 implementation 的区别:https://www.jianshu.com/p/8962d6ba936e
dependencies {
    // 基类封装
    implementation project(':library:base')
    // 控件封装
    implementation project(':library:widget')
    // 友盟封装
    implementation project(':library:umeng')

    // 依赖 libs 目录下所有的 jar 和 aar 包
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')


    //ZXing的精简极速版 https://github.com/jenly1314/ZXingLite
    implementation 'com.github.jenly1314:zxing-lite:2.1.1'

    // 快速实现新手引导层的库 https://github.com/huburt-Hu/NewbieGuide
    implementation 'com.github.huburt-Hu:NewbieGuide:v2.4.0'

    //日历 https://github.com/huanghaibin-dev/CalendarView
    implementation 'com.haibin:calendarview:3.7.1'

    //XPopup:https://github.com/li-xiaojun/XPopup
    implementation 'com.github.li-xiaojun:XPopup:2.7.6'

    //官方的flex布局控件
    implementation 'com.google.android:flexbox:1.0.0'

    // 权限请求框架:https://github.com/getActivity/XXPermissions
    implementation 'com.github.getActivity:XXPermissions:12.3'

    // 标题栏框架:https://github.com/getActivity/TitleBar
    implementation 'com.github.getActivity:TitleBar:9.2'

    // 吐司框架:https://github.com/getActivity/ToastUtils
    implementation 'com.github.getActivity:ToastUtils:9.5'

    // 网络请求框架:https://github.com/getActivity/EasyHttp
    implementation 'com.github.getActivity:EasyHttp:10.2'
    // OkHttp 框架:https://github.com/square/okhttp
    // noinspection GradleDependency
    implementation 'com.squareup.okhttp3:okhttp:3.12.13'

    // Json 解析框架:https://github.com/google/gson
    implementation 'com.google.code.gson:gson:2.8.8'
    // Gson 解析容错:https://github.com/getActivity/GsonFactory
    implementation 'com.github.getActivity:GsonFactory:5.2'

    // Shape 框架:https://github.com/getActivity/ShapeView
    implementation 'com.github.getActivity:ShapeView:6.0'

    // AOP 插件库:https://mvnrepository.com/artifact/org.aspectj/aspectjrt
    implementation 'org.aspectj:aspectjrt:1.9.6'

    // 图片加载框架:https://github.com/bumptech/glide
    // 官方使用文档:https://github.com/Muyangmin/glide-docs-cn
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

    // 沉浸式框架:https://github.com/gyf-dev/ImmersionBar
    implementation 'com.gyf.immersionbar:immersionbar:3.0.0'

    // 手势 ImageView:https://github.com/Baseflow/PhotoView
    implementation 'com.github.Baseflow:PhotoView:2.3.0'

    // Bugly 异常捕捉:https://bugly.qq.com/docs/user-guide/instruction-manual-android/?v=20190418140644
    implementation 'com.tencent.bugly:crashreport:3.4.4'
    implementation 'com.tencent.bugly:nativecrashreport:3.9.2'

    // 动画解析库:https://github.com/airbnb/lottie-android
    // 动画资源:https://lottiefiles.com、https://icons8.com/animated-icons
    implementation 'com.airbnb.android:lottie:4.1.0'

    // 上拉刷新下拉加载框架:https://github.com/scwang90/SmartRefreshLayout
    implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'
    implementation 'com.scwang.smart:refresh-header-material:2.0.3'

    // 日志打印框架:https://github.com/JakeWharton/timber
    implementation 'com.jakewharton.timber:timber:4.7.1'

    // 指示器框架:https://github.com/ongakuer/CircleIndicator
    implementation 'me.relex:circleindicator:2.1.6'

    // 腾讯 MMKV:https://github.com/Tencent/MMKV
    implementation 'com.tencent:mmkv-static:1.2.10'

    // 内存泄漏监测框架:https://github.com/square/leakcanary
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
    previewImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
    // 工具类:https://github.com/Blankj/AndroidUtilCode
    implementation 'com.blankj:utilcodex:1.31.0'
    //eventbus:https://github.com/greenrobot/EventBus
    implementation 'org.greenrobot:eventbus:3.1.1'
    annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.1.1'
    //轮播图:https://github.com/youth5201314/banner
    implementation 'io.github.youth5201314:banner:2.2.1'
    // 轮播图:https://github.com/bingoogolapple/BGABanner-Android
    // 多语种:https://github.com/getActivity/MultiLanguages
    // 悬浮窗:https://github.com/getActivity/XToast
    // 日志输出:https://github.com/getActivity/Logcat
    // 工具类:https://github.com/Blankj/AndroidUtilCode
    // 二维码:https://github.com/bingoogolapple/BGAQRCode-Android
    // 跑马灯:https://github.com/sunfusheng/MarqueeView
    // 对象注解:https://www.jianshu.com/p/f1f888e4a35f
    // 对象存储:https://github.com/leavesC/DoKV
    // 多渠道打包:https://github.com/Meituan-Dianping/walle
    // 设备唯一标识:http://msa-alliance.cn/col.jsp?id=120
    // 嵌套滚动容器:https://github.com/donkingliang/ConsecutiveScroller
    // 隐私调用监控:https://github.com/huage2580/PermissionMonitor
    //RKGlassDevice Glass 设备管理模块
    implementation 'com.rokid.axr:glassdevice-phone:1.0.4'
}