Can we have multiple apps in one Android Studio project?

前端 未结 5 1186
小蘑菇
小蘑菇 2020-12-07 14:07

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 righ

相关标签:
5条回答
  • 2020-12-07 14:16

    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.

    0 讨论(0)
  • 2020-12-07 14:19

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

    • Create a new module by right clicking on your project -> new -> module
    • Select phone and tablet module

    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.

    0 讨论(0)
  • 2020-12-07 14:21

    Yes, you can by creating 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.


    You can also instead create an additional library module, ideal for a separate code base with common code 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')
        ···
    }
    ···
    
    0 讨论(0)
  • 2020-12-07 14:30

    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.

    0 讨论(0)
  • 2020-12-07 14:41

    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

    0 讨论(0)
提交回复
热议问题