0

我需要构建一个使用风味创建的应用程序并创建一个指向另一种风味的applicationId的动态变量(因为内部库的代码使用其他应用程序的 applicationId),但我不知道该怎么做。

这是示例代码:

defaultConfig {
    applicationId "com.sample.mycompany"
}

buildTypes {
    release {
    }
    qualif {
        applicationIdSuffix = ".qual"
    }
    debug {
        applicationIdSuffix = ".dev"
    }
}

flavorDimensions "client", "nature"
    productFlavors {
        ClientA {
            dimension "client"
            applicationIdSuffix = ".A"
        }
        ClientB {
            dimension "client"
            applicationIdSuffix = ".B"
        }

        NatureX {
            dimension "nature"
            applicationIdSuffix = ".X"
        }
        NatureY {
            dimension "nature"
            applicationIdSuffix = ".Y"
            // A buildconfigField variable here to get com.sample.mycompany[client].X[buildTypes]
        }
        NatureZ {
            dimension "nature"
            applicationIdSuffix = ".Z"
            // A buildConfigField variable here to get com.sample.mycompany[client].X[buildTypes]
        }
}

当我使用 Build Variant 进行编译时:ClientANatureYDebug ,最终的applicationIdcom.sample.mycompany.AYdev

我想要一个带有 buildConfigField 的动态变量(或在 Java 中检索新变量的其他东西),它是com.sample.mycompany.AXdev

我想得到最终的 applicationId 并将当前自然编译维度的 applicationIdSuffix 替换为 .X 并在新变量中获取结果但我不知道如何。你能帮助我吗 ?

4

1 回答 1

0

固定:

buildConfigField "String", "VAL_SHARE_TO_RECEIVER_APP_ID", "APPLICATION_ID.replace(\".Y\", \".X\")"
于 2018-12-13T16:45:11.713 回答