Android Studio打包设置分支

故事扮演 提交于 2021-02-07 10:38:44
打包设置
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'
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!