Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 798
Deer Avatar asked Jul 26 '16 15:07

Deer


People also ask

How can I share data between two Android apps?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.

Can I open two projects in Android Studio?

To open multiple projects simultaneously in Android Studio, go to Settings > Appearance & Behavior > System Settings, in the Project Opening section, choose Open project in new window.

Can we share project in Android Studio?

Once Android Studio selects the folder for you, it opens an Explorer, and selects a folder within your project folder. To create a zip you have to Right click it and select: “Send To/Compressed (zipped) folder”. With that, you get a “. zip” file that you can take with you, send over mail, share…


1 Answers

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.

like image 72
Hephaestus Avatar answered Sep 22 '22 15:09

Hephaestus