在插件的gradle应用变种获取包名 [英] Getting package name of application variant in gradle plugin

查看:3729
本文介绍了在插件的gradle应用变种获取包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个插件的Gradle,增加了一个新的任务为每个应用程序变种。这个新的任务需要应用变种的包名。

I'm building a gradle plugin that adds a new task for every application variant. This new task needs the package name of the application variant.

这是我目前的code,它停止使用最新版本的Andr​​oid插件的gradle工作:

This is my current code, which stopped working with the most recent version of the android gradle plugin:

private String getPackageName(ApplicationVariant variant) {
    // TODO: There's probably a better way to get the package name of the variant being tested.
    String packageName = variant.generateBuildConfig.packageName

    if (variant.processManifest.packageNameOverride != null) {
        packageName = variant.processManifest.packageNameOverride
    }
    packageName
}

本已经停止了最新版本的Andr​​oid插件的工作,因为更改构建配置处理。这似乎是一个黑客之前,无论如何,所以我并不感到惊讶它停止工作。有没有去取包名称规范的方式?

This has stopped working in the most recent version of the android plugin because of changes to the build config processing. It seemed like a hack before anyway, so I'm not surprised it stopped working. Is there a canonical way to fetch the package name?

推荐答案

我用这样的:

// Return the packageName for the given buildVariant
def getPackageName(variant) {
    def suffix = variant.buildType.packageNameSuffix
    def packageName = variant.productFlavors.get(0).packageName
    if (suffix != null && !suffix.isEmpty() && suffix != "null") {
        packageName += suffix
    }
    return packageName
}

这篇关于在插件的gradle应用变种获取包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆