[英]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:
com.example.pear_staging
(note the "_") com.example.pear_staging
(注意“_”)com.example.pear
com.example.pear
com.example.banana_staging
(note the "_")com.example.banana_staging
(注意“_”)com.example.banana
com.example.banana
: com.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 "_")风味pearStaging :
com.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:例如:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.