Tuesday, August 2, 2016

ProductFlavors 和 debug release

Android Studio  如果做了多个项目的区分, 就是你的项目,被多家公司使用,使用的包名不唯一。  这个时候,你没有办法通过名字区分  是正式版本 还是测试版本?

但是,有的时候 需求需要, 当你的测试包和正式包 包名一样的时候,你真的没有办法处理!

解决方案:

在build.gradle 中 使用 resValue

这样设置你的build.gradle
apply plugin: 'com.android.application'
android {
    println("===============  android")

    compileSdkVersion 23    buildToolsVersion "23.0.2"
    defaultConfig {

        println("===============  defaultConfig")

        applicationId "test.geekhades.com.productflavorsanddebug"        minSdkVersion 19        targetSdkVersion 23        versionCode 1        versionName "1.0"    }

    signingConfigs {

        debug {
            println("===============  signingConfigs.debug")

        }

        release {
            println("===============  signingConfigs.release")
        }
    }

    buildTypes {

        debug {
            println("===============  buildTypes.debug")

            applicationIdSuffix project.APP_IS_DEBUG            resValue 'string', 'app_name', "测试版"            buildConfigField "boolean", "IS_DEBUG", "true"            IS_RELEASE=false            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)
        }

        release {
            println("===============  buildTypes.release")

            minifyEnabled false            IS_RELEASE=true            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)

            buildConfigField "boolean", "IS_DEBUG", "false"            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }

    productFlavors {



        mlw {
            println("===============  productFlavors.mlw")

            //mlw  美丽屋            applicationId project.MLW_PACKAGE_NAME            versionCode Integer.parseInt(project.MLW_VERSION_NAME.replace(".",""))
            versionName project.MLW_VERSION_NAME            manifestPlaceholders = [umengHolder: "anzhi"]

            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)

            resValue 'string', 'app_name', "美丽屋经纪人"        }

        gjb {
            println("===============  productFlavors.gjb")

            //gjb  管家宝            applicationId project.GJB_PACKAGE_NAME            versionCode Integer.parseInt(project.GJB_VERSION_NAME.replace(".",""))
            versionName project.GJB_VERSION_NAME
            manifestPlaceholders = [umengHolder: "anzhi"]

            println("===============  buildTypes.debug IS_RELEASE" + project.IS_RELEASE)

            resValue 'string', 'app_name',  "管家宝"        }

    }


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.4.0'}


在buildType.debug 中设置 app_name

这个时候设置的 debug的版本


在 ProductFlavors 中设置的是正式版本的label

解决!




No comments:

Post a Comment