2

I am new to Android Studio, Right now I have create a project and added a module in it as a library project but when i push the project to Git the library project gets also added to the repository instead in other new Git repository.

I just want to know that how can i create a sub module in Android Studio like we do in Eclipse via egit plugin, and how to push it to a completely new Git repository, practically this sub module would actually be my library project.

Ishant Sagar
  • 111
  • 2
  • 7

1 Answers1

2

i also had the same situation where i had to develop a library and the application in parallel. For this you can use android library project as git submodule to your application project, in that way you can manage both your application project and the library project.So here is my solution:

Step 1: create an android library project.

its similar to creating normal application project. just go through this google doc : https://developer.android.com/studio/projects/android-library.html

step 2: create a repository for the library project in git (GitHub/BitBucket)

step 3: add the library codes to the version control system (VCS)

android studio adding codes to VCS

step 4: push your library codes to the git repository

pushing code to git

Step 5: now create your Android application project

Step 6: Add the project to version control system (VCS)

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

adding un-versioned files to vcs

Step 8: From android studio project terminal add git sub-module using command

git submodule add HHHH://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 9: You will get a message for 'unregisterd vcs root detected'. click on add root

un-versioned vcs root detected popup

now you can see multiple git repositories at the right bottom of the android studio

multiple git selection available

Step 10: goto file menu — project structure

Step 11: click ‘+’ on left top

adding new module

Step 12: select ‘Import Gradle Project’

importing library project

Step 13: select the sub-module folder

Step 14: give the actual sub-module project name

enter image description here

Step 15: Sync

Step 16: Now in the application project builg.gradle file add

compile project(‘:lib-name’)

within the dependencies section

Step 17: 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 :)

I have published this as my blog: https://medium.com/@deepakpk/how-to-add-a-git-android-library-project-as-a-sub-module-c713a653ab1f#.mt6dlng5n

Deepak PK
  • 59
  • 6
  • Please don't just include a link to the solution - explain the solution in the post. Also you should probably disclose if this is a link to *your* website – CallumDA Jan 08 '17 at 12:18
  • 1
    Still working very well. Thanks, i have not find anything else explaining how to do this. – ThiagoYou Oct 03 '19 at 16:26