The best way to reuse code is to make it as a library. Sometimes you need to develop the library and the applications in parallel, in these situation the library might get changes and additions from multiple projects and we need to manage them, and the best way to manage the code is to use git and submodules.
Here i am going to show you how to add a android library project as a submodule to an Android application project, and both being maintained by git.
Prerequisite:
- An Android Library project under a repository (Git / BitBucket)
Step 1: Create Android project
Step 2: Add the project to version control system (VCS)

Step 3: From the bottom version control menu, add all the Unversioned Files to the VCS

Step 4: From android studio project terminal add git sub-module
git submodule add https://XXX@bitbucket.org/YYY/ZZZ.git
- make sure the sub module save location folder name is different than the original library project name, else you might get conflicts.
Step 5: You will get a message like this

click on add root
now you can see multiple git repositories at the right bottom of the android studio

Step 6: goto file menu — project structure
Step 7: click ‘+’ on left top

Step 8: select ‘Import Gradle Project’

Step 9: select the sub-module folder

Step 10: give the actual sub-module project name

Step 11: Sync
Step 12: Now in the application project builg.gradle file add
compile project(‘:lib-name’)
within the dependencies section

Step 13: gradle sync & build project
Now you have an application project in git, which uses a library which is added to it as a submodule in git. Now you can develop on the application and on the library parallelly. Its better to keep a separate branch of the library for an application so as not to conflict with other application usage, and if the library code changes can be used in other projects also you can make a PR request to the main branch of the library.
Happy Coding :)