Android Studio,如何将自己的 git 存储库添加为库项目(子模块)? [英] Android Studio, how to add my own git repository as a library project(sub module)?

查看:71
本文介绍了Android Studio,如何将自己的 git 存储库添加为库项目(子模块)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android Studio 的新手,现在我已经创建了一个项目并在其中添加了一个模块作为库项目,但是当我将项目推送到 Git 时,库项目也被添加到存储库中,而不是在其他新的 Git 存储库中.

我只想知道如何像在 Eclipse 中通过 egit 插件一样在 Android Studio 中创建子模块,以及如何将其推送到全新的 Git 存储库,实际上这个子模块实际上是我的库项目.

解决方案

我也遇到过同样的情况,我不得不并行开发一个库和应用程序.为此,您可以将 android 库项目用作应用程序项目的 git 子模块,这样您就可以管理您的应用程序项目和库项目.所以这是我的解决方案:

第一步:创建一个android库项目.

它类似于创建普通的应用程序项目.只需浏览此谷歌文档:

第 4 步:将您的库代码推送到 git 存储库

第 5 步:现在创建您的 Android 应用程序项目

第 6 步:将项目添加到版本控制系统 (VCS)

第 7 步:从底部的版本控制菜单中,将所有未版本控制的文件添加到 VCS

第 8 步:从 android studio 项目终端使用命令添加 git 子模块

git 子模块添加 HHHH://XXX@bitbucket.org/YYY/ZZZ.git确保子模块保存位置文件夹名称与原始库项目名称不同,否则可能会发生冲突.

第 9 步:您将收到检测到未注册的 vcs root"的消息.点击添加root

现在你可以在android studio的右下方看到多个git仓库

第十步:转到文件菜单 — 项目结构

第 11 步:点击左上角的+"

第 12 步:选择导入 Gradle 项目"

第十三步:选择子模块文件夹

第十四步:给出实际的子模块项目名称

第 15 步:同步

第 16 步:现在在应用程序项目 builg.gradle 文件中添加

编译项目(‘:lib-name’)

在依赖项部分

第 17 步:gradle 同步 &构建项目

现在您在 git 中有一个应用程序项目,它使用一个库作为 git 中的子模块添加到其中.现在您可以在应用程序和库上并行开发.最好为应用程序保留一个单独的库分支,以免与其他应用程序使用冲突,如果库代码更改可以在其他项目中使用,您也可以向库的主分支提出 PR 请求.

快乐编码:)

我已将此作为我的博客发布:https://medium.com/@deepakpk/how-to-add-a-git-android-library-project-as-a-sub-module-c713a653ab1f#.mt6dlng5n

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.

解决方案

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

这篇关于Android Studio,如何将自己的 git 存储库添加为库项目(子模块)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆