Androidマルチチャネルパッケージとカスタムパッケージファイル名

1693 ワード

パッケージ出力をパッケージ化するときは、パッケージ名バージョン番号+チャネル名+パッケージ日付+など、パッケージファイル名をカスタマイズすることを望んでいます.apk.これを例にgradleカスタムパッケージファイルスクリプトを書きます.
    //     
    productFlavors {

        m360 { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "360"] }
        yingyongbao { manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao"] }
    }

    //         
    buildTypes {
        debug {
            signingConfig signingConfigs.release
        }
        release {
            //    log
            buildConfigField("boolean", "LOG_DEBUG", "true")
            // Zipalign   
            zipAlignEnabled true
            debuggable false
            minifyEnabled false
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //       apk    
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        //    
                        productFlavors.each { flavor ->
                            def myFlavor = flavor
                          //       
                            def fileName = "${applicationId}_v${defaultConfig.versionName}_${myFlavor.manifestPlaceholders.UMENG_CHANNEL_VALUE}_${releaseTime()}_release.apk"
                            output.outputFile = new File(outputFile.parent, fileName)
                        }
                    }
                }
            }
        }
    }