Android productFlavors使用

 productFlavors 打不同的包,生产环境与测试环境动态更改变量。

  flavorDimensions "country" //纬度

    productFlavors {
        china {
            applicationId "com.example.fluttertoandroid"
            dimension "country"
            buildConfigField "String" , "channel" , '"1"' //变量值
        }
        usa {
            applicationId "com.example.fluttertoandroid"
            dimension "country"
            buildConfigField "String" , "channel" , '"2"' //变量值
        }
    }
productFlavors {
        pro{
            applicationId "com.xxx.xxx"
            versionCode 1
            versionName "1.0.1"
            buildConfigField 'String', 'SERVER_URL', '"https://xxx.xxx.com"'
            buildConfigField 'boolean', 'useLive', 'true'
            resValue "string", "app_name", "xxx"
            manifestPlaceholders = [
                    PACKAGE_NAME    : "com.xxx.xxx",//包名(权限配置等相关)
                    app_icon        : "@mipmap/icon_desk",//图标
            ]
        }
    }

buildConfigField 在代码中的使用:

    btn.setText(BuildConfig.channel + "")

resValue在清单文件中的使用: 

android:label="@string/app_name"

manifestPlaceholders 在清单文件中的使用:

android:name="${PACKAGE_NAME}"
android:icon="${app_icon}"
android:authorities="${FILE_PROVIDER}"
android:value="${BD_MAP_KEY}"

 


版权声明:本文为qq_39238370原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。