You need to extract these components in a separate module :
A module is a discrete unit of functionality that you can compile, run, test, and debug yourself.
Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation. However, the modules exist and function only in the context of the project.
Then include this module in all the projects he uses.
In fact, you can create the module yourself in an independent "library" project . And add it as a dependency for all of his projects.
Further, you can publish the output of the open source library project as .aar or .jar in central, jcenter and other public maven repositories. Then other people will also be able to use your module.
Some important points to keep in mind when creating Android library projects:
Resources (strings, layouts, xmls, images) of the library will be combined with the resources of the final project during assembly. However, your R class will remain under the name of your module.
Some attributes from the library manifest file can be combined with the attribute of the final project (for example, for <application> ). Thus, the library module must have a minimal manifest file, in which, at most, is the name of the package.
You can include the sample application project in the library module, but do not redo the sample application project using the library. This will cause problems for someone who is building an application using your library.
source share