68

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 project = Eclipse workspace
  • Android Studio module = Eclipse project

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?

Thanks!

QED
  • 9,803
  • 7
  • 50
  • 87
Bahramdun Adil
  • 5,907
  • 7
  • 35
  • 68

5 Answers5

81

Yes, you have two options:

Option 1: Create an addition app module

  1. First create your standard Phone & Tablet Android project, including the auto-generated app module.
  2. Add a new app module: File > New > New Module ... > Phone & Tablet Module
  3. Complete the wizard and name your Application app2 for instance.

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

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.

Option 2: Create an addition library module

This is ideal for creating a separate library that is isolated from the app, and can be shared across more apps (or other projects):

  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.

Now libgoodstuff and app will reside in the same project.

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'

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')
    ···
}
···
Stephan Henningsen
  • 3,665
  • 1
  • 22
  • 29
  • 2
    I think, this is the best way to do this.i need to keep common module with common code. – Vikas Pandey Jan 17 '17 at 08:39
  • 3
    This is one of the answers that actually answer the question. Other "answers" purely asking too much "why". – Chen Li Yong Jun 14 '19 at 07:24
  • is that possible to dependent an app module to another app module to sharing activities of one? – user3648435 Sep 14 '19 at 09:29
  • Hi, if I do this and hit build, I notice both app and app2 being built, why? I do have only app2 selected in the dropdown – urSus Jan 26 '20 at 15:50
  • @urSus: Build - whether issued by green hammer-button or hotkey - will build the entire project which includes app and app2. The Build button located to the left of the module drop-down is actually not related to this drop-down; however, the Run, Debug, Coverage, and Stop buttons to the right are. This is not very clear in the UI, I'll give you that. (Maybe there ought to be a vertical separator between the hammer and the drop-down, but maybe someone decided that would clutter the tool bar. You fell victim for the classic "this is wrong but it looks better" design decision ;) – Stephan Henningsen Jan 27 '20 at 08:25
  • oh man, I often just click build to see if it compiles, without actually installing the apk -.- – urSus Jan 27 '20 at 12:31
15

Yes you can. Inside your project if you want to create a new app do the following:

Now you will be able to run either app. This is an excellent way to share code between two apps as it allows you to keep and develop your libraries in one location.

enter image description here

enter image description here

dawis11
  • 820
  • 1
  • 9
  • 24
Munaz
  • 336
  • 2
  • 9
10

You can definitely have multiple app modules in the same Android Studio project. Having said that, I've yet to find a reason to define multiple app modules in a project.

  • If you need different version of the same app, Gradle's build variant is powerful enough to satisfy perhaps 99% of the use-cases (I have a project with a dozen variants, each with its own custom code/res).
  • If you are writing different apps then it's better to make each its own project so apps don't inadvertently change each other's behaviour.

Not sure what you mean by "is every app in Android Studio independent as Eclipse", but each module is its own world by default unless dependencies to other modules are explicitly defined.

Kai
  • 15,284
  • 6
  • 51
  • 82
  • 1
    Thanks for your reply. I know that we can have multiple apps of different version in one project, here only versions are different, app is the same. But I say can we have different apps in one project or not, are they disturb together or not. If we can have, then it is better to use one project for many apps or one project per app? – Bahramdun Adil Sep 06 '15 at 07:33
  • As mentioned in the answer, there's nothing against having multiple apps in one project, and that these apps(aka modules) are independent by default. As a rule, only put multiple apps in the same project if they are somehow closely related. – Kai Sep 06 '15 at 07:50
  • 2
    What about two apps that share a common library? This is a really common requirement, but seemingly unsupported by Android Studio. – Rupert Rawnsley Nov 18 '15 at 11:14
  • @RupertRawnsley that's a limitation I've found as well, using symbolic link may be a solution, haven't actually tried it though – Kai Nov 18 '15 at 15:08
  • We use multiple modules for tv and the regular app and all the other logic like networking and things like that are in submodules that are shared dependencies for both. – James andresakis Mar 24 '16 at 18:09
  • Im fairly confused about this, prefer using it like Eclipse workspaces. I develop just for my own stack of apps that run on Android TV sticks, there are 4 apps that I maintain that always go on these sticks together, no shared libraries of my own. How can apps inadvertently change each other's behaviour? Am I always compiling in all the dependancies in the Gradle file to each app even if not needed? – Adamz May 01 '16 at 16:09
  • For development of combined Android Wear and Android Phone apps, sharing both apps in a single project works very well. As mentioned above, a major benefit is having a shared code module that can be used by both apps. Android Studio handles this very nicely. – Hephaestus Aug 23 '16 at 20:51
  • One “release” app and a dozen of testing apps for different subsystems is a valid scenario – Lothar Dec 28 '21 at 03:14
6

Adding this as an answer since I don't have enough reputation for comments yet.

For the answer to your question - Check this question that I have raised. Is this the same boat you were in ?

TL;DR

I was able to have multiple apps in the same Android Studio Project, build and run them without any issues. Another member corroborated my claims in the comments on the Question.

@Android Studio Pros : Please check the above link and add your insights. This seems to be a confusing aspect.

My Take

I think I agree with @Kai's answer. But there are instances where we want multiple apps to have common library dependencies and don't want to duplicate the library dependencies. Wouldn't multiple apps be fine as long as the common library dependencies have ONLY common code and nothing else. The separate modules hold the individual app related code and that's where the differentiation is.

Community
  • 1
  • 1
acthota
  • 557
  • 5
  • 22
  • 4
    What do you mean with _we want multiple apps to have common library dependencies_? If those dependencies are available in public repos you should use a declarative dependency in the gradle build script. If you are talking about sharing your own code in several applications, I recommend to also use the declarative dependency system either having a private artifact repository or installing the dependencies in your local artifact repository using mavenLocal() – José González Feb 17 '16 at 18:03
  • 3
    Yes. But I would want to have an easy way to edit the code of the library module as well in the same Android Studio Project without having to switch between projects and dealing with pushing/uploading the library artifacts to the artifact repository and updating the application modules to pick up the updates. – acthota Feb 19 '16 at 06:41
  • Ok, I see... in this case you are simultaneously developing the main application and the library that depends on. A quick Google search revealed this: http://stackoverflow.com/questions/16622410/how-do-i-add-a-library-project-to-the-android-studio-and-use-itsome-asked-dont. Any way, I would do this only temporarily and move to the artifact based mechanism as soon as possible. – José González Feb 24 '16 at 15:22
  • 1
    The artifact based mechanism.. Perfectly makes sense .. down the line. Isn't it amazing how diverse our requirements are :) – acthota Jan 22 '17 at 01:57
3

Yes, it is possible. As the existing answers showed, it’s quite straightforward to create additional application module in the same Android Studio project. So I’ll try to answer underlying question why anyone might need it.

It’s certainly not worth it to put multiple completely independent apps in one project.

However, if you app is big enough, you might benefit from putting separate features into separate modules. You can also create a separate executable app module for each feature, so that you can:

  • launch/debug each feature separately
  • save some time on every compilation/dexing/putting everything into a single apk
  • encourage teams/developers to work independently, and even in separate repositories.

The main app module can be used only to combine existing features together.

I’ve recently created an article demonstrating this approach where I tried to explain everything in more details: https://medium.com/@domplebump/multiple-application-modules-in-one-android-project-36e86ceb8a9

Andrei Buneyeu
  • 6,662
  • 6
  • 35
  • 38