我们可以在一个 Android Studio 项目中拥有多个应用程序吗? [英] Can we have multiple apps in one Android Studio project?

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

问题描述

我正在使用 Android Studio 开发 Android 应用程序.但是我听说在 Android Studio 中最好在单个(每个应用程序一个项目)中只有一个应用程序,如果这样的话,那么为多个项目打开多个框架会非常浪费.但是当我搜索时我发现

I am using Android Studio for developing Android apps. But I have heard in Android Studio it is better to have only one app in a single (one project per app) if that is right, then it will be very wasteful to open many frames for many projects. But when I searched I found that

  • Android Studio 项目 = Eclipse 工作区
  • Android Studio 模块 = Eclipse 项目

现在,如果这是真的,则意味着 Android Studio 也可以支持多应用项目.如果是,那么 Android Studio 中的每个应用程序是否都像 Eclipse 中一样独立(即它们不会通过共享任何文件或设置来相互干扰)?或者我们可以在一个项目中拥有多个应用程序吗?如果可以的话,有什么需要注意的吗?

Now, if this is true, it means that Android Studio also can support a multi-app project. If yes, then, is every app in Android Studio independent like in Eclipse (i.e. they do not disturb each other by sharing any file or setting)? Or can we have many apps in a single project? If we can then is there any point to take care of?

谢谢!

推荐答案

是的,您有两个选择:

  1. 首先创建您的标准电话 &平板电脑 Android 项目,包括自动生成的 app 模块.
  2. 添加一个新的应用模块:文件 >新 >新模块... >电话及平板电脑模块
  3. 例如完成向导并为您的应用程序命名为 app2.

现在您将在同一个项目中同时拥有 appapp2.

Now you'll have both app and app2 in the same project.

要实际运行 app2,您首先需要在 Android Studio 顶部工具栏的下拉菜单中选择它,在开始"和调试"图标旁边.您也可以通过运行配置执行此操作:运行 >运行... >编辑配置...并修改模块.

To actually run app2 you first need to select it in the pull-down menu in the top toolbar of Android Studio, next to the Start and Debug icons. You can also do this though Run Configurations: Run > Run... > Edit Configurations... and modifying Module.

这是一个单独的代码库的理想选择,在更多应用或其他项目中共享公共代码:

This ideal for a separate code base with common code shared across more apps or other projects:

  1. 添加一个新的模块:文件>新 >新模块... >Java 库.
  2. 完成向导并为您的库起一个好名字,例如 libgoodstuff.
  1. Add a new library module: File > New > New Module ... > Java Library.
  2. Complete the wizard and give your library a good name, like libgoodstuff.

现在 libgoodstuffapp 将驻留在同一个项目中.

Now libgoodstuff and app will reside in the same project.

要使 app 源依赖于 libgoodstuff,您首先必须将库模块添加到项目 settings.gradle 中,使其看起来像这个:

To make app sources depend on libgoodstuff, you first have to add the library module to the project settings.gradle to look something like this:

include ':app', ':libgoodstuff'

然后在 app/build.gradle 中你必须像这样依赖库模块:

Then in app/build.gradle you have to depend on the library module like this:

apply plugin: 'com.android.application'

···
dependencies {
    ···
    implementation project(path: ':libgoodstuff')
    ···
}
···

这篇关于我们可以在一个 Android Studio 项目中拥有多个应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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