Deer
Deer

Reputation: 175

Share Code Between 2 Projects in Android Studio

I have 2 apps, one for the clients and one for the managers. They are based on similar code (Classes, Layouts, Activities).

How do I "share" those files between the 2 apps? So if I change a shared class or a layout, the change would be visible in both apps. (So I make only ONE change, and not have to make two).

I work on Android Studio.

Thank you.

Upvotes: 11

Views: 6024

Answers (1)

Hephaestus
Hephaestus

Reputation: 5093

Here is an excellent discussion about sharing code: StackOverFlow #24592027 I'm doing a pair of apps for Wear and Phone products and the Android docs recommend to build both in the same project file as separate modules. Based on the comments in the link, I created a third Module called 'sharedcode' that I can then link between the Wear and Phone apps. This give me a common shared code module. I think the point is that your two apps will also need to be combined into a single project. Each app gets its own compilation target, but they then both share the same code. Then go into the dependency settings (File | Project Structure; tab to Dependencies) and set each app to depend on the SharedCode module. Good luck.

Upvotes: 3

Related Questions