完整的build.gradle(包含多渠道,混淆,debug, release, apk命名规则)

apply plugin: 'com.android.application'


def releaseTime() {
    return new Date().format("yyyy.MM.dd", TimeZone.getTimeZone("UTC"))
}
android {
    compileSdkVersion 27
    defaultConfig {
        multiDexEnabled true
        applicationId "com.xxx"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//        testApplicationId 'com.plan_solve.farmlandassistant'
//        signingConfig signingConfigs.release
        javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
        //版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
        flavorDimensions "versionCode"

    }
    //签名
    signingConfigs {
        debug {
            // 自己的签名文件(可从module setting设置路径)
            storeFile file('../tgzj.jks')
            storePassword "tgzj2018"
            keyAlias "tgzj2018"
            keyPassword "tgzj2018"
        }
        release {// 自己的签名文件
            storeFile file('../tgzj.jks')
            storePassword "tgzj2018"
            keyAlias "tgzj2018"
            keyPassword "tgzj2018"
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true// false表示不混淆,true表示混淆
            shrinkResources true //移除无用的resource文件
            //如果用eclipse里面的proguard.cfg,直接替换 proguard-rules.pro 即可
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            signingConfig signingConfigs.release
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def fileName
                    def date = new Date()
                    def formattedDate = date.format('yyyyMMdd')
                    if (variant.buildType.name.equals('release')) {
                        fileName = "xxx${variant.mergedFlavor.versionName}_release_${formattedDate}.apk"
                    } else if (variant.buildType.name.equals('debug')) {
                        fileName = "xxx${variant.mergedFlavor.versionName}_debug_${formattedDate}.apk"
                    }
                    outputFileName = fileName;
                }
            }
        }
        debug {

        }

    }
    buildToolsVersion '27.0.3'
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    //渠道Flavors,配置不同风格的app,
    productFlavors {
        yingyongbao {
            minSdkVersion 14
            applicationId 'com.plan_solve.farmlandassistant'
//            signingConfig signingConfigs.release
        }
        wandoujia {
            minSdkVersion 14
            applicationId 'com.plan_solve.farmlandassistant'
        }
        baidu {
            minSdkVersion 14
            applicationId 'com.xxx'
        }
        xiaomi {
            minSdkVersion 14
            applicationId 'com.xxx'
            targetSdkVersion 27
        }
        huawei {
            minSdkVersion 14
            applicationId 'com.xxx'
            targetSdkVersion 27
        }
        offical {
            minSdkVersion 14
            applicationId 'com.xxx'
        }
        productFlavors.all {
            flavor -> flavor.manifestPlaceholders = [BUGLY_APP_CHANNEL_VALUE: name]
        }
    }


}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
    implementation project(':libPulltoRefresh')
    implementation 'com.contrarywind:Android-PickerView:3.2.2'
    implementation 'com.zxy.android:tiny:0.0.6'
    implementation 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation files('libs/AMap_Search_V5.1.0_20170517.jar')
    implementation files('libs/Android_Map3D_SDK_V5.2.0_20170602.jar')
    implementation files('libs/fastjson-1.2.5.jar')
    //图片处理,选择,压缩,剪裁
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'com.soundcloud.android.crop:lib_crop:1.0.0'
    implementation 'com.darsh.multipleimageselect:multipleimageselect:1.0.5'
    implementation 'me.shaohui.advancedluban:library:1.3.2'
    implementation 'com.sun.mail:android-mail:1.6.0'
    implementation 'com.sun.mail:android-activation:1.6.0'
    implementation 'com.android.support:multidex:1.0.3'
    //    implementation project(':calendarlibrary')
}

你可能感兴趣的:(完整的build.gradle(包含多渠道,混淆,debug, release, apk命名规则))