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

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

android {
B
Blankj 已提交
17
    compileSdkVersion Config.compileSdkVersion
B
Blankj 已提交
18
    defaultConfig {
B
Blankj 已提交
19 20 21 22 23
        minSdkVersion Config.minSdkVersion
        versionCode Config.versionCode
        versionName Config.versionName
        applicationId Config.applicationId + suffix
        targetSdkVersion Config.targetSdkVersion
B
Blankj 已提交
24
        multiDexEnabled true
B
Blankj 已提交
25
        resValue "string", "app_name", Config.appName + suffix
B
Blankj 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    }

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

    packagingOptions {
        exclude 'META-INF/*'
    }

    dexOptions {
B
Blankj 已提交
44
        preDexLibraries true
B
Blankj 已提交
45 46
        javaMaxHeapSize "8g"
        maxProcessCount 8
B
Blankj 已提交
47
        dexInProcess = true
B
Blankj 已提交
48 49 50 51 52 53
    }
}


dependencies {
    // LeakCanary
B
Blankj 已提交
54 55 56
    debugImplementation Config.depConfig.leakcanary.android.dep
    debugImplementation Config.depConfig.leakcanary.support_fragment.dep
    releaseImplementation Config.depConfig.leakcanary.android_no_op.dep
B
Blankj 已提交
57

B
Blankj 已提交
58 59 60 61 62 63 64 65 66
    // 根据 Config.pkgConfig 来依赖所有 pkg
    for (def entrySet : ConfigUtils.getApplyPkgs().entrySet()) {
        api entrySet.value.dep
    }

    // 如果 Config.pkgConfig 不为空,说明可能导入了部分 pkg,
    // 那么可能有些 api 没有实现,需要导入 mock 层的 api
    if (!Config.pkgConfig.isEmpty()) {
        api Config.depConfig.feature.mock.dep
B
Blankj 已提交
67
    }
B
Blankj 已提交
68 69
}

B
Blankj 已提交
70 71 72
def getSuffix() {
    if (project.path == ":app:launcher:app") return ""
    return project.path.replace(":", "_").substring(4, project.path.length() - 4)
B
Blankj 已提交
73 74
}

B
Blankj 已提交
75
def configSigning() {
B
Blankj 已提交
76 77 78 79

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

B
Blankj 已提交
80
    GLog.d("${project.toString()} sign start...")
B
Blankj 已提交
81
    project.android {
B
Blankj 已提交
82 83 84 85 86 87 88 89 90 91 92 93
        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 已提交
94
    GLog.d("${project.toString()} sign end...")
B
Blankj 已提交
95 96
}

B
Blankj 已提交
97 98
def configApkName() {
    project.android.applicationVariants.all { variant ->
B
Blankj 已提交
99
        if (variant.buildType.name != "debug") {
B
Blankj 已提交
100 101 102
            def artifact = variant.getPackageApplicationProvider().get()
            artifact.outputDirectory = new File("${rootDir.path}/apk")
            artifact.outputScope.apkDatas.forEach { apkData ->
B
Blankj 已提交
103
                apkData.outputFileName = "util" + suffix +
B
Blankj 已提交
104
                        (variant.flavorName == "" ? "" : ("_" + variant.flavorName)) +
B
Blankj 已提交
105
                        "_" + variant.versionName.replace(".", "_") +
B
Blankj 已提交
106
                        "_" + variant.buildType.name +
B
Blankj 已提交
107 108 109 110 111
                        ".apk"
            }
        }
    }
}