android studio3 多渠道打包及编译速度优化等

直接看code

module app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.wlh.androidencrypt"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        flavorDimensions "versionCode"     //多渠道打包 必须加,不然 报错 All flavors must now belong to a named flavor dimension.
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("boolean", "enableLog", "true") // for java BuildConfig.enableLog 控制log
        }
        debug {
            ext.enableCrashlytics = false
            ext.alwaysUpdateBuildId = false
            buildConfigField("boolean", "enableLog", "true")
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }
    }


    //多渠道打包
    productFlavors{
        googleplay{}

        dev {
            manifestPlaceholders = [channel: "dev"]
            resConfigs "en","xxhdpi"
        }

        official {
            manifestPlaceholders = [channel: "official"]
            resConfigs "en","xxhdpi"
        }

        wandoujia {
            manifestPlaceholders = [channel: "wandoujia"]
            resConfigs "en","xxhdpi"
        }

        xiaomi {
            manifestPlaceholders = [channel: "xiaomi"]
            resConfigs "en","xxhdpi"
        }

        "360" {
            manifestPlaceholders = [channel: "360"]
            resConfigs "en","xxhdpi"
        }

        tencent {
            manifestPlaceholders = [UMENG_CHANNEL: "Tencent"]
            //resConfigs "en","xxhdpi"
        }

    }

    //自动输出自定义名字
//    applicationVariants.all { variant ->
//        variant.outputs.each { output ->
//            output.outputFile = new File(
//                    output.outputFile.parent + "/${variant.buildType.name}","lihua-${variant.buildType.name}-${variant.versionName}-${variant.productFlavors[0].name}.apk".toLowerCase())
//        }
//    }
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            outputFileName = "AndroidEncrypt_${variant.productFlavors[0].name}_${variant.buildType.name}_v${variant.versionName}.apk"
        }
    }
    //禁止png crunching, 禁止构建时默认压缩图片的方法
    aaptOptions {
        cruncherEnabled false
    }

    // dex预处理和最多八线程
    dexOptions{
    //   incremental true
        preDexLibraries true
        maxProcessCount 8
    }

    //关闭不需要task
    tasks.whenTaskAdded { task ->
        if(task.name.contains("lint")
            || task.name.contains("Aidl")
            || task.name.contains("mockableAndroidJar")
            || task.name.contains("UnintTest")
            || task.name.contains("AndroidTest")
            || task.name.contains("Ndk")
            || task.name.contains("Jni")
        ){
            task.enabled = false
        }

    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

gradle.properties

org.gradle.jvmargs=-Xmx1536m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true

android studio3 多渠道打包及编译速度优化等_第1张图片

github ok地址:

https://github.com/wanlihua2006/MultiMarket_opt

你可能感兴趣的:(android)