我需要在单个项目中管理两个不同的客户端代码,因此我使用了productFlavors并为每个客户端定义了风格。
现在的问题是两者的源代码库相同,但需要定义不同的
applicationId
,例如
我如何制作风味,以便代码保持相同且
appId
不同?
Android 将为您想要在所有构建变体之间共享的所有内容创建
main/
源集和目录,因此无需在您的情况下创建新的源集。
您可以将
applicationIdSuffix
用于不同的构建变体,在计算变体的最终应用程序 ID 时,将其附加到“基本”应用程序 ID。
例如:-
flavorDimensions "appMode"
productFlavors {
free {
dimension "appMode"
applicationIdSuffix ".free" //the application id of 'free' is com.example.com.free
}
paid {
dimension "appMode"
applicationIdSuffix ".paid"//the application id of 'paid' is com.example.com.paid
}
}
applicationIdSuffix 将附加到包名称(基本应用程序 id)后,
com.example.com
是上例中的包名称。
添加代码块集
applicationId
,如下所示:
productFlavors {
abc {
resValue "string", "build_type", "Version " + defaultConfig.versionName
applicationId "com.abc"
}
def {
resValue "string", "build_type", "Version " + defaultConfig.versionName
applicationId "com.def"
}