5

I have an Android Studio project which consists of a login activity with relative style, manifest, IntentService and other stuff.

I want to insert this little project in many other apps, what is the best way to proceed ? Is Module the right way ?

The ultimate goal is still to easy maintenance, such as if one day the server should change URL, I would not have to make changes in any application that uses this login activity :-)

marco
  • 3,193
  • 4
  • 28
  • 51

2 Answers2

6

You need to extract these components in a separate module:

A module is a discrete unit of functionality which you can compile, run, test and debug independently.

Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation. However, modules exist and are functional only in the context of a project.

Then, include that module in all projects using it.

In fact, you can create the module in an independent "library" project of its own. And add it as a dependency for all projects using it.

Going a step further, you can publish the output of an open source library project as .aar or .jar on maven central, jcenter and other public repositories. Then other people will also be able to use your module.

Some important points to remember when creating android library projects:

  1. The resources (strings, layouts, xmls, images) of a library will be merged with those of final project on build. Still your module's R class will stay under your module's package name.

  2. Some attributes from manifest file of library might be merged to that of final project (like that of <application> ). So, a library module should have a minimal manifest file, with at most, the package name.

  3. You may include an example application project inside a library module, but do not redestribute the example app project with library. It will cause trouble for someone building an application using your library.

Community
  • 1
  • 1
S.D.
  • 29,290
  • 3
  • 79
  • 130
0

I think that what you need to do is to export your original project first:

File>>Export

Then go to your new project and import the original one. Dont forget to amend the setContentView() method to point to your original activity(the one you imported)

and finally dont forget your intent method! if you have any issues let me know and i will create a detailed answer for you but i think that you will be ok!

Raul Gonzales
  • 866
  • 1
  • 15
  • 28