5

I'm moving from Eclipse to android studio and this is my set up in eclipse: I have several Android app projects, depending on several library projects (some shared) all within one workspace. In Android studio I first started creating a project per app, but quickly realized that I would have to have the library projects as modules within each project that uses them. This would mean duplicating the library projects and including them in each app, which is highly redundant and would require maintaining multiple copies of the libraries.

So I switched to having all my apps and libraries as modules within the same project. This works for building but creates other problems such as version control issues since each module lives in a separate version control repository.

What is the cleanest way to have this setup? And the real question is, can I have separate projects in AS that share the same external library projects?

Inn0vative1
  • 2,014
  • 3
  • 27
  • 43
  • In gradle build system you don't need to download all your library modules inside the project. you can use the maven dependencies to include them in your project to compile. – Piyush Agarwal Feb 06 '14 at 11:17

1 Answers1

3

NOTE

With the release of Android Studio 0.5.0, this answer is obsolete, but I'll leave it below for reference. For more up-to-date instructions, see How to share a single library source across multiple projects


In Android Studio, it's difficult to have shared library projects, because currently it's a limitation that all modules in a project must live under the same root folder; it seems like you found this out when you tried to solve your problem by making one big project that includes everything. We're working on trying to lift this limitation.

The best answer right now is to make the library modules separate projects and have them publish to a local Maven repository, and have the dependent projects pull them in from that repo. This means that you can't work on your app + library module sources from the context of a single project, unfortunately. A bigger disadvantage is that source attachments for those library modules doesn't work yet, so if you're trying to debug your app, you'll have difficulty stepping into code in the libraries.

I know this isn't a very great answer, but at this stage of Android Studio's evolution, it's probably the best we can do. We know yours is a fairly common use case, and it's a priority for us to support it.

Community
  • 1
  • 1
Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • Thanks for the answer. I suppose Maven artifacts would work but I'd lose the convenience of accessing related projects at the same time. After using my setup having related "projects" as modules in the same project for a couple of days I find that does suffice for my current needs and besides version control issues I haven't hit any major snags. In this case Eclipse workspace = AS project and Eclipse project = AS module. – Inn0vative1 Feb 08 '14 at 04:38
  • We are waiting for you guys to fix the issue. We are trying to use git-submodule to overcome it. It is not very straight forward regarding git operations. – SXC Feb 26 '14 at 00:33
  • Hi Scott, will you guys eventually allow an application project reference shared library projects out side the root folder of the application project? Do you have ETA? – SXC Feb 26 '14 at 17:27
  • You can track its progress at https://code.google.com/p/android/issues/detail?id=56367. As you can see from the comments, the changes to support it are being checked in and should appear in the next release. – Scott Barta Feb 26 '14 at 17:31
  • Is this situation anywhere improved in Android Studio 0.5? – Neoh Mar 07 '14 at 06:23
  • Yes, answered your other question and edited my answer here to link to it. – Scott Barta Mar 08 '14 at 00:07