Android Studio, how to add my own git repository as a library project(sub module)?

做~自己de王妃 提交于 2019-11-28 09:42:19

问题


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.


回答1:


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)

step 4: push your library codes to the git repository

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

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

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

Step 10: goto file menu — project structure

Step 11: click ‘+’ on left top

Step 12: select ‘Import Gradle Project’

Step 13: select the sub-module folder

Step 14: give the actual sub-module project name

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



来源:https://stackoverflow.com/questions/27717728/android-studio-how-to-add-my-own-git-repository-as-a-library-projectsub-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!