[英]How to Build different APK files using different databases in Android using Gradle tool?
We have a platform to read poetry with a SQLITE Database say SHAKESPEARE.DB . 我们拥有一个使用SQLITE数据库SHAKESPEARE.DB读取诗歌的平台。 We also have another poetry say Wordsworth.DB.
我们还有另外一首诗说《华兹华斯》。 So for each poetry database we want to create a separate application like Shakespeare.apk and wordsworth.apk.
因此,对于每个诗歌数据库,我们都希望创建一个单独的应用程序,例如Shakespeare.apk和wordsworth.apk。
During build we want to mention the Database and mention the name of the APK. 在构建期间,我们要提及数据库并提及APK的名称。
How do we Change Database during android build through gradle and deploy different APK's 我们如何在Android构建过程中通过gradle更改数据库并部署不同的APK
I would want to Create and Deploy Database specific APK using Gradle ? 我想使用Gradle创建和部署数据库特定的APK吗?
Step #1: Use a consistent means of embedding the database in the app. 步骤#1:使用一致的方式将数据库嵌入到应用程序中。 For this answer, I will assume that you are using
SQLiteAssetHelper
, with the database packaged as words.db
in assets/
. 对于此答案,我将假定您使用的是
SQLiteAssetHelper
,数据库打包为assets/
words.db
。
Step #2: Create two product flavors for your app in your app/
module's build.gradle
file. 步骤2:在您的
app/
模块的build.gradle
文件中为您的应用程序创建两种产品口味。 For this answer, I will call these flavors vanilla
and chocolate
: 对于这个答案,我将这些口味称为
vanilla
和chocolate
:
productFlavors {
vanilla {
applicationId "com.commonsware.android.gradle.hello.vanilla"
}
chocolate {
applicationId "com.commonsware.android.gradle.hello.chocolate"
}
}
(replace the applicationId
values with ones more relevant to your project) (将
applicationId
值替换为与您的项目更相关的值)
Step #3: Create a sourceset for each flavor ( app/src/vanilla
, app/src/chocolate/
). 步骤#3:为每种口味(
app/src/vanilla
, app/src/chocolate/
)创建一个源集。
Step #4: Put a different words.db
in assets/
of the flavor ( app/src/vanilla/assets/words.db
, app/src/chocolate/assets/words.db
). 步骤#4:将不同的
words.db
放入words.db
的assets/
中( app/src/vanilla/assets/words.db
, app/src/chocolate/assets/words.db
)。
Now, when you build vanilla
, it will use the vanilla
edition of words.db
. 现在,当您构建
vanilla
,它将使用words.db
的vanilla
版本。 When you build chocolate
, it will use the chocolate
edition of words.db
. 制作
chocolate
,它将使用words.db
的chocolate
版本。 No Java code changes are required. 无需更改Java代码。 You can also put different resources in those flavor-specific sourcesets, for different icons, labels, etc. Because you have different
applicationId
values, both flavors can be installed on your test devices at the same time, and both flavors can be distributed through app distribution channels like the Play store. 您还可以在这些特定于口味的源集中放置不同的资源,以用于不同的图标,标签等。由于您具有不同的
applicationId
值,因此可以同时在测试设备上安装这两种口味,并且可以通过app分发这两种口味Play商店等发行渠道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.