Android Studio打包设置分支

打包设置
flavorDimensions("channel")
    productFlavors {
        demo {
            manifestPlaceholders = [APP_NAME: "@string/app_name_demo"]
            applicationId "com.example.demo"
            buildConfigField 'String', 'SERVICE_ITEM', "\"0\""
            dimension "channel"
        }

        release{
            manifestPlaceholders = [APP_NAME: "@string/app_name"]
            applicationId "com.example.release"
            buildConfigField 'String', 'SERVICE_ITEM', "\"1\""
            dimension "channel"
        }
    }

    //自定义apk文件名
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                // def npstr = android.buildTypes.release.minifyEnabled ? "" : "_np"
                def flavor = variant.productFlavors[0]
                def typeName
                switch (flavor.name) {
                    case "demo":
                        typeName = "测试版"
                        break
                    case "release":
                        typeName = "正式版"
                        break
                    default:
                        break
                }
                outputFileName = "DEMO${releaseTime()}_v${flavor.versionName}_${typeName}.apk"
            }
        }
    }

    buildTypes {
        debug {
            // applicationIdSuffix ".debug"
            manifestPlaceholders = [APP_NAME: "@string/app_name_debug"]
        }
        release {
            manifestPlaceholders = [APP_NAME: "@string/app_name"]
            // 是否进行混淆
            minifyEnabled false
            // 混淆配置文件
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_26280383/article/details/113677925