简体   繁体   English

GoogleServices - 如何使用flavorDimensions 为每种风味组合设置不同的applicationId?

[英]GoogleServices - How to set different applicationId for each flavor combination using flavorDimensions?

I have old apps using non compliant applicationId.我有使用不兼容的 applicationId 的旧应用程序。 I trying to migrate them with flavorDimensions to share so common assets & code.我尝试使用 flavorDimensions 迁移它们以共享如此常见的资产和代码。 I have this flavors setup:我有这个口味设置:

defaultConfig {
    applicationId "com.example"
}

flavorDimensions 'fruit', 'env'

productFlavors {
    pear {
        dimension 'fruit'
    }

    banana {
        dimension 'fruit'
    }

    staging {
        dimension 'env'
    }

    prod {
        dimension 'env'
    }
}

I would like to have these applicationId by flavor combination:我想通过风味组合来获得这些 applicationId:

  • pearStaging : com.example.pear_staging (note the "_") pearStagingcom.example.pear_staging (注意“_”)
  • pearProd : com.example.pear pearProdcom.example.pear
  • bananaStaging : com.example.banana_staging (note the "_")香蕉com.example.banana_staging 注意“_”)
  • bananaProd : com.example.banana香蕉com.example.bananacom.example.banana

I have tried to use applicationIdSuffix :我曾尝试使用applicationIdSuffix

productFlavors {
    pear {
        dimension 'fruit'
        applicationIdSuffix 'pear'
    }

    banana {
        dimension 'fruit'
        applicationIdSuffix 'banana'
    }

    staging {
        dimension 'env'
        applicationIdSuffix '_staging'
    }

    prod {
        dimension 'env'
    }
}

but suffixes are separated with dot by default.但后缀默认用点分隔。 So it's generate wrong applicationId, ex:所以它生成了错误的applicationId,例如:

flavor pearStaging : com.example.pear._staging (note the "." before "_")风味pearStagingcom.example.pear._staging (注意“_”之前的“.”)

I saw answers on this thread: How to set different applicationId for each flavor combination using flavorDimensions?我在这个线程上看到了答案: 如何使用 flavorDimensions 为每种风味组合设置不同的 applicationId? They talk about a workaround using mergedFlavor.setApplicationId(...) to override applicationId at the end.他们讨论了一种解决方法,在最后使用mergedFlavor.setApplicationId(...)覆盖 applicationId。 But this not working if I use in combination with google services gradle plugin .但如果我与谷歌服务 gradle 插件结合使用,这将不起作用。

Because during plugin process phase, I got this error:因为在插件过程阶段,我收到了这个错误:

* What went wrong:
Execution failed for task ':app:processPearStagingDebugGoogleServices'.
> No matching client found for package name 'com.example'

As you see, it use default applicationId/package name, not the appId overrided in android.applicationVariants.all phase.如您所见,它使用默认的 applicationId/package 名称,而不是在android.applicationVariants.all阶段覆盖的 appId。

So there is a better way to defined my applicationId per flavor combination that works with google services task?那么有更好的方法来定义我的 applicationId 每个风味组合与谷歌服务任务一起使用吗? (I need to keep these applicationId with "_", can't change it). (我需要用“_”保留这些applicationId,不能改变它)。

It is not possible with the current way that google services gradle plugin works.谷歌服务 gradle 插件的当前工作方式是不可能的。 Maybe there's a way to feedback to Google about that, but meanwhile, the only way to achieve the application IDs with "_" is to rename the application ID after the apk is built.也许有一种方法可以反馈给谷歌,但同时,使用“_”实现应用程序 ID 的唯一方法是在构建 apk 后重命名应用程序 ID。 So, the flavour-specific application ID would be built with "."因此,特定风味的应用程序 ID 将使用“.”构建。 separators first, then rename the application ID after the apk is built.首先分隔符,然后在构建 apk 后重命名应用程序 ID。

This could be done with the standard procedure of using apktool to open the apk, change the application ID to what you need, then repackage with apktool, zipalign, re-sign, etc. If it may be too tedious, there are GitHub projects that attempt to do the same, but they may not work on all apks.这可以通过使用apktool打开apk的标准程序来完成,将应用程序ID更改为您需要的,然后使用apktool重新打包,zipalign,重新签名等。如果可能太繁琐,有GitHub项目尝试做同样的事情,但它们可能不适用于所有 apk。

For example:例如:

  1. https://github.com/testwhat/PackageRenamer https://github.com/testwhat/PackageRenamer
  2. https://github.com/sjitech/ApkRename https://github.com/sjitech/ApkRename

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用flavorDimensions为每种口味组合设置不同的applicationId? - How to set different applicationId for each flavor combination using flavorDimensions? 使用 Gradle Kotlin-DSL 时,如何使用 flavorDimensions 为每个风味组合设置不同的 applicationId? - How to set different applicationId for each flavor combination using flavorDimensions when using Gradle Kotlin-DSL? 检索不同口味的applicationId? - Retrieve the applicationId of a different flavor? 使用风味维度时设置 Android applicationId 的正确方法是什么? - What is the correct way to set Android applicationId when using flavor dimensions? Android-如何获取Flavor的ApplicationId - Android - How To Get Flavor's ApplicationId 不同风味维度如何设置signingConfig? - How to set signingConfig for different flavor dimensions? 我在哪里可以为多口味构建指定每个组合的 applicationId? - Where can I specify applicationId per-combination for a multi-flavor build? Android 配置特定于 2 个风味维度的每个组合 - Android configuration specific to each combination of 2 flavor dimensions 如何为每个Android ABI设置产品风味中的CmakeLists路径? - How to set CmakeLists path in product flavor for each Android ABI? 风味,如何改变不同风味的主要活动 - flavor , how to change different flavor main activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM