简体   繁体   English

如何使用Gradle工具在Android中使用不同的数据库构建不同的APK文件?

[英]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 : 对于这个答案,我将这些口味称为vanillachocolate

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/vanillaapp/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.dbassets/中( app/src/vanilla/assets/words.dbapp/src/chocolate/assets/words.db )。

Now, when you build vanilla , it will use the vanilla edition of words.db . 现在,当您构建vanilla ,它将使用words.dbvanilla版本。 When you build chocolate , it will use the chocolate edition of words.db . 制作chocolate ,它将使用words.dbchocolate版本。 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.

相关问题 Gradle-如何为每种口味指定不同的Android * .apk构建位置? - Gradle - how to specify different Android *.apk build location for each flavor? 在android eclipse中使用一个代码构建两个不同的apk - Build two different apk using one single code in android eclipse 无法使用 Unity.Gradle 构建 android apk 失败 - Not able to build android apk using Unity.Gradle build fail 有没有办法为 Android 中的不同构建变体配置维护不同的 .gradle 文件? - Is there a way to maintain different .gradle files for different build variant configurations in Android? 如何使用Gradle构建系统创建两个或三个不同的构建,每个构建都指向不同的服务器? - How to create a two or three different build using Gradle build system, each build pointing to different server? 如何在 android 中的应用程序 build.gradle 中使用 productFlavors 定义不同的 compileSdkVersion - How to define different compileSdkVersion using productFlavors in app build.gradle in android Intune是否支持使用包装工具使用Xamarin构建Android apk? - Does Intune support Android apk build with Xamarin using Wrapping Tool? 如何通过gradle构建不同的android变种 - how to build different variants of android through gradle 在离线模式下使用Gradle在Redhat中构建Android APK - Build Android APK in Redhat using Gradle in Offline mode 使用gradle构建系统创建测试Android apk - Create testing Android apk using gradle build system
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM