build.gradle添加打包配置

gradle一键打包配置全部,如下(不需要的可以不添加):

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.sample.demo"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        flavorDimensions "versionCode"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            storeFile file('') //签名文件地址
            storePassword '' //密码
            keyAlias '' //别名
            keyPassword '' //密码
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            //是否优化zip
            zipAlignEnabled true
            //移除无用的resource文件
            shrinkResources true
            signingConfig signingConfigs.release
        }
    }

    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
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "${variant.productFlavors[0].name}-${defaultConfig.versionName}-${defaultConfig.versionCode}" +
                    "-${releaseTime()}-${variant.buildType.name}.apk"
        }
    }

    productFlavors {
        Sample_Project {} //区分打包(自己做区分也可做多渠道打包)
    }
}

//获取当前打包的时间
def static releaseTime() {
    return new Date().format("yyyy.MM.dd-HH.mm")
}

你可能感兴趣的:(build.gradle添加打包配置)