You have several different options.
One option is to maintain your libraries as separate projects and compile them into an archive format such as a JAR or AAR; JAR files are for pure Java libraries, and AARs are for Android libraries (which contain code that accesses the Android API and / or has Android resources). As noted in the comments, AAR does not force you to publish your code in the world more than JAR files; it is simply an archive file format whose files may be local to your computer or your organization.
Using this archive file, you can include it in other projects. If you are part of an organization with several developers, you may find it convenient to use the repository manager to publish and maintain these libraries within your organization , and you can use the Maven specifications for coordination to include libraries in your projects that you do not need to manually copy to your development machine.
The disadvantage of this approach is that it is a little more difficult for it to make changes to these libraries: you need to download the project, make changes, create an archive and distribute the archive.
Another approach is to save the library as a source module, as in Eclipse. You noticed that Android Studio will make a copy of the module if you import it through the user interface, but if you bypass the user interface and make changes to the build scripts directly, you can do what you want, namely use the module in place and share one copy several projects. To do this, work in the settings.gradle file and add this:
include ':module_name' project(':module_name').projectDir = new File(settingsDir, '../relative/path/to/module')
I would strongly recommend that you not use the pure relative path here; in this example, the path is bound to the settingsDir
variable provided by Gradle, which is defined as the directory where settings.gradle is located. If you use a pure relative path (i.e. are not attached to anything), you depend on the fact that the working directory is the same in all environments where the build file (command line against Android Studio against the CI server) is executed, which is not good to assume.
source share