Android Studio - 在单个项目中具有共同依赖项的多个 Android 应用程序 [英] Android Studio - Multiple android apps with common dependencies in a single project

查看:43
本文介绍了Android Studio - 在单个项目中具有共同依赖项的多个 Android 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的安卓应用 A 和 B.A和B是同一个项目中的模块

I have two different android apps A and B. A and B are modules in the same project

两者都依赖于一个库模块 Z,而 Z 本身又依赖于另外两个库模块 X 和 Y

Both have a dependency on a library module Z which itself depends on two other library modules X and Y

  • A -> Z
  • B -> Z

Z -> X, Y

现在这个问题的公认答案 表示单个 Android Studio 项目不能有多个应用.

Now the accepted answer to this question says that a single Android Studio project cannot have multiple apps.

奇怪的是,我能够构建这两个应用程序(在一个 android studio 项目中)并在我的手机上很好地运行它们.我在这里遗漏了一些明显的东西吗?

Strangely I am able to build these two apps (in a single android studio project) and run them on my phone pretty well. Am I missing something obvious here ?

一个 android studio 项目可以包含多个应用吗?

  1. 如果答案是否定的,为什么?
  2. 如果答案是肯定的,有什么问题吗?

推荐答案

一个 Android 项目确实可以有多个应用程序,尽管如果多个应用程序不相关,您可能会争论在一个项目中拥有多个应用程序的好处.

A single Android project can indeed have multiple apps, although you could argue about the benefits of having several apps in a single project if they are unrelated.

无论如何,如果您有同一个应用程序的多个版本并且它们之间存在一些差异(目标设备、品牌......),这是完全合理的.在这种情况下,Gradle 构建系统允许您拥有构建变体(每个构建变体都是产品风格构建类型的组合).根据官方文档(配置 Gradle 构建 > 使用构建变体):

Anyway, this is perfectly reasonable in case you have several versions of the same app with some differences among them (target devices, branding...). In that case the Gradle build system allows you to have build variants (each build variant being a combination of a product flavor and a build type). According to the official documentation (Configuring Gradle Builds > Work with build variants):

构建系统使用产品风格来创建应用的不同产品版本.您的应用程序的每个产品版本可能具有不同的功能或设备要求.构建系统还使用构建类型将不同的构建和打包设置应用于每个产品版本.每个产品风味和构建类型组合形成一个构建变体.构建系统为您应用的每个构建变体生成不同的 APK.

The build system uses product flavors to create different product versions of your app. Each product version of your app can have different features or device requirements. The build system also uses build types to apply different build and packaging settings to each product version. Each product flavor and build type combination forms a build variant. The build system generates a different APK for each build variant of your app.

这篇关于Android Studio - 在单个项目中具有共同依赖项的多个 Android 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆