Gradle 来自另一个 applicationId 风格的变量

Gradle variable from another applicationId flavor

我需要构建一个使用风格 创建的应用程序,并创建一个指向另一个风格 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.A.Y.dev

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

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

已修复:

buildConfigField "String", "VAL_SHARE_TO_RECEIVER_APP_ID", "APPLICATION_ID.replace(\".Y\", \".X\")"