Android Gradle自动打包随笔

2020-02-19  本文已影响0人  imkobedroid

配置打包脚本

android{
    
    
  defaultConfig {
      .....
      flavorDimensions "versionCode"
    }
    
    
    
    
    
    signingConfigs {
        release {
            keyAlias '...'
            keyPassword '...'
            storeFile file('../app/key')
            storePassword '....'
        }
    }
    
    
    
    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    def fileName = "Android_${getCurrentTime()}_V${defaultConfig.versionName}_release.apk"
                    outputFileName = fileName
                }
            }
        }

        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    def fileName = "Android_${getCurrentTime()}_V${defaultConfig.versionName}_debug.apk"
                    outputFileName = fileName
                }
            }

        }
    }
    
    
    
    //渠道包
      productFlavors {
        longyuan {
            applicationId "com.test.app"
            versionCode defaultConfig.versionCode
            versionName defaultConfig.versionName
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "pgy"]
            manifestPlaceholders = [APP_NAME: "appname"]
        }
    }
    
    
    ....
    
}



static def getCurrentTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}


注意

gradle需要分别打包 assesbleRelease和assesbleDebug时候需要gradle版本最新,例如

classpath 'com.android.tools.build:gradle:3.5.3'

才会有:


image.png
上一篇下一篇

猜你喜欢

热点阅读