Android 配置输出Apk名称和路径、渠道

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.fivesixseven.floatwindowtest"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

//    applicationVariants.all { variant ->
//        variant.outputs.all {
//            // 自定义输出路径
//            variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + File.separator + "outputs")
//            // 自定义文件名{示例:AppName-Flavor-debug-v1.0.0_201807301409}
//            outputFileName = "AppName-${variant.flavorName}-${variant.buildType.name}-v${variant.versionName}_${time()}.apk"
//        }
    // 爱好的
//    }
    def createTime = new Date().format("YYYYMMddHHmmss", TimeZone.getTimeZone("GMT+08:00"))
    flavorDimensions 'huawei', 'xiaomi'
    productFlavors {
        huawei_p30 {
            dimension = 'huawei'
            applicationId = 'com.huaiwei.huaweip'
            applicationIdSuffix = 'com.huaiwei.huaweip'
            versionCode = 567
            versionName = '5.6.7'
            versionNameSuffix = '5.6.7'
            targetSdkVersion 28
            minSdkVersion 24
        }

        xiao_nine {
            dimension = 'xiaomi'
            applicationId = 'com.xiaomi.xiaominine'
            applicationIdSuffix = 'com.xiaomi.xiaominine'
            versionCode = 123
            versionName = '1.2.3'
            versionNameSuffix = '1.2.3'
            targetSdkVersion 24
            minSdkVersion 24
        }
    }


    android.applicationVariants.all {
        variant ->
            variant.outputs.all {
                output ->
                    outputFileName = "${variant.flavorName}_${variant.name}_${variant.versionCode}_${variant.versionName}_" + createTime + ".apk"
            }

            variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + File.separator + "outputs")
    }


}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

 

你可能感兴趣的:(移动端,安卓)