buildApp.gradle 3.8 KB
Newer Older
B
Blankj 已提交
1 2 3 4
apply {
    plugin "com.android.application"
    plugin "kotlin-android"
    plugin "kotlin-android-extensions"
B
Blankj 已提交
5 6
    if (Config.depConfig.plugin_bus.isApply) {
        plugin Config.depConfig.plugin_bus.pluginId
B
Blankj 已提交
7
    }
B
Blankj 已提交
8 9
    if (Config.depConfig.plugin_api.isApply) {
        plugin Config.depConfig.plugin_api.pluginId
B
Blankj 已提交
10
    }
B
Blankj 已提交
11 12
}

B
Blankj 已提交
13 14
configSigning()
configApkName()
B
Blankj 已提交
15

B
Blankj 已提交
16 17 18 19
if (Config.depConfig.plugin_bus.isApply) {
    bus {
        onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
    }
B
Blankj 已提交
20 21
}

B
Blankj 已提交
22 23 24 25
if (Config.depConfig.plugin_api.isApply) {
    api {
        onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
    }
B
Blankj 已提交
26 27
}

B
Blankj 已提交
28
android {
B
Blankj 已提交
29
    compileSdkVersion Config.compileSdkVersion
B
Blankj 已提交
30
    defaultConfig {
B
Blankj 已提交
31
        minSdkVersion Config.minSdkVersion
B
Blankj 已提交
32 33 34 35
        versionCode Config.versionCode
        versionName Config.versionName
        applicationId Config.applicationId + suffix
        targetSdkVersion Config.targetSdkVersion
B
Blankj 已提交
36 37 38 39 40 41 42
        multiDexEnabled true
    }

    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
B
Blankj 已提交
43
            applicationIdSuffix ".debug"
B
Blankj 已提交
44
            resValue "string", "app_name", Config.appName + suffix + ".debug"
B
Blankj 已提交
45
        }
B
Blankj 已提交
46

B
Blankj 已提交
47 48 49
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
B
Blankj 已提交
50
            resValue "string", "app_name", Config.appName + suffix
B
Blankj 已提交
51 52 53 54 55 56 57 58
        }
    }

    packagingOptions {
        exclude 'META-INF/*'
    }

    dexOptions {
B
Blankj 已提交
59
        preDexLibraries true
B
Blankj 已提交
60 61
        javaMaxHeapSize "8g"
        maxProcessCount 8
B
Blankj 已提交
62
        dexInProcess = true
B
Blankj 已提交
63 64 65 66 67 68
    }
}


dependencies {
    // LeakCanary
B
Blankj 已提交
69 70 71
    debugImplementation Config.depConfig.leakcanary_android.dep
    debugImplementation Config.depConfig.leakcanary_support_fragment.dep
    releaseImplementation Config.depConfig.leakcanary_android_no_op.dep
B
Blankj 已提交
72

B
Blankj 已提交
73 74
    debugImplementation Config.depConfig.lib_utildebug.dep
    releaseImplementation Config.depConfig.lib_utildebug_no_op.dep
B
Blankj 已提交
75

B
Blankj 已提交
76 77 78 79 80
    // 根据 Config.pkgConfig 来依赖所有 pkg
    for (def entrySet : ConfigUtils.getApplyPkgs().entrySet()) {
        api entrySet.value.dep
    }

B
Blankj 已提交
81 82
    if (Config.depConfig.feature_mock.isApply) {
        api Config.depConfig.feature_mock.dep
B
Blankj 已提交
83
    }
B
Blankj 已提交
84 85
}

B
Blankj 已提交
86
def getSuffix() {
B
Blankj 已提交
87 88
    if (project.path == ":feature:launcher:app") return ""
    return project.path.replace(":", "_").substring(":feature".length(), project.path.length() - ":app".length())
B
Blankj 已提交
89 90
}

B
Blankj 已提交
91
def configSigning() {
B
Blankj 已提交
92 93 94 95

    File signPropertiesFile = file("${rootDir.path}/sign/keystore.properties")
    if (!signPropertiesFile.exists()) return

B
Blankj 已提交
96
    GLog.d("${project.toString()} sign start...")
B
Blankj 已提交
97
    project.android {
B
Blankj 已提交
98 99 100 101 102 103 104 105 106 107 108 109
        Properties properties = new Properties()
        properties.load(new FileInputStream(signPropertiesFile))
        signingConfigs {
            release {
                storeFile new File(signPropertiesFile.getParent(), properties['keystore'])
                storePassword properties['storePassword']
                keyAlias properties['keyAlias']
                keyPassword properties['keyPassword']
            }
        }
        buildTypes.release.signingConfig signingConfigs.release
    }
B
Blankj 已提交
110
    GLog.d("${project.toString()} sign end...")
B
Blankj 已提交
111 112
}

B
Blankj 已提交
113 114
def configApkName() {
    project.android.applicationVariants.all { variant ->
B
Blankj 已提交
115
        if (variant.buildType.name != "debug") {
B
Blankj 已提交
116 117 118
            def artifact = variant.getPackageApplicationProvider().get()
            artifact.outputDirectory = new File("${rootDir.path}/apk")
            artifact.outputScope.apkDatas.forEach { apkData ->
B
Blankj 已提交
119
                apkData.outputFileName = "util" + suffix +
B
Blankj 已提交
120
                        (variant.flavorName == "" ? "" : ("_" + variant.flavorName)) +
B
Blankj 已提交
121
                        "_" + variant.versionName.replace(".", "_") +
B
Blankj 已提交
122
                        "_" + variant.buildType.name +
B
Blankj 已提交
123 124 125 126 127
                        ".apk"
            }
        }
    }
}