Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议提供获取当前Variant的方法,并将 apkNameFormat 中flavorName改名为channelName #53

Closed
zero-li opened this issue Sep 4, 2018 · 2 comments

Comments

@zero-li
Copy link

zero-li commented Sep 4, 2018

当前项目有生成aaa, bbb, ccc三个不同产品的配置

   flavorDimensions "mode"

    productFlavors {
        aaa {
            dimension "mode"
            applicationId "com.example.aaa"
            signingConfig signingConfigs.aaa
        }

        bbb{
            dimension "mode"
            applicationId "com.example.bbb"
            signingConfig signingConfigs.bbb
        }

        ccc{
            dimension "mode"
            applicationId "com.example.ccc"
            signingConfig signingConfigs.ccc
        }
    }

多渠道包的命名规则,默认为:${appName}-${versionName}-${versionCode}-${flavorName}-${buildType}

现需求为

def getCurrentFlavorName= "${getCurrentFlavorName()}"
apkNameFormat = getCurrentFlavorName + '-${buildType}-V${versionName}-C${versionCode}-${buildTime}-${flavorName}'
import java.util.regex.Matcher
import java.util.regex.Pattern
def getCurrentFlavorName() {
    Gradle gradle = getGradle()
    String  tskReqStr = gradle.getStartParameter().getTaskRequests().toString()

    Pattern pattern;

    if( tskReqStr.contains( "assemble" ) )
        pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
    else if(tskReqStr.contains( "channel" ))
        pattern = Pattern.compile("channel(\\w+)(Release|Debug)")
    else
        pattern = Pattern.compile("generate(\\w+)(Release|Debug)")

    Matcher matcher = pattern.matcher( tskReqStr )

    if( matcher.find() )
        return matcher.group(1).toLowerCase()
    else
    {
        println "NO MATCH FOUND"
        return "";
    }
}

现在获取getCurrentFlavorName 比较麻烦,希望提供简易方法获取mVariant,并将 apkNameFormat 中flavorName改名为channelName

 def keyValue = [
                'appName'    : project.name,
                'flavorName' : channel,  //----------->channelName
                'buildType'  : mVariant.buildType.name,
                'versionName': mVariant.versionName,
                'versionCode': mVariant.versionCode,
                'appId'      : mVariant.applicationId,
                'buildTime'  : buildTime
               'mVariant' : mVariant,  // add
               'flavorName' : mVariant.name,  //add

        ]

多次执行生成渠道包,会将前一次生成的渠道包删除,可有设置不删除的配置?

@ltlovezh
Copy link
Collaborator

嗯,感谢建议,我尽快实现哈

@chenyusheng
Copy link

嗯,感谢建议,我尽快实现哈
哪个版本会实现?我也有这样的需要,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants