The problem is the Android Project which I have has in all 3 modules viz. 1 main & other supporting modules.
Currently I pushed the whole project to BitBucket which includes the modules too, but I'm confused if I should just push modules in different repos & not in a single repo like I have did.
If different repos is the best way to go head, then how should I link all the 3 repos to represent as a single project.
If it is one Android project then you should probably use submodules. Read this tutorial to know more about how to create submodules:
https://git-scm.com/book/en/v2/Git-Tools-Submodules
Then you can use
git submodule foreach git pull
To pull all submodules recursively or
git pull --recurse-submodules
I recommend you to create another Bitbucket repos for each supporting module then you could use git submodules to link them with your main project or just upload the artifacts to a maven repo like jcenter, sonatype or bintray, then you can compile they as dependencies in build.gradle. I prefer the second option.
Git submodule:
http://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/
Related
I have a project that uses modules. One of the modules that I need to use is inside another repository. In the future, I will connect that module into my project using mavenCentral, but not now.
I want to have my MODULE from another repository inside my PROJECT without adding the MODULE into my PROJECT GIT. And I should be able to switch between git repos and commit the changes into their corresponding repositories.
So far I did this:
-- added MODULE origin inside PROJECT like so.
git remote add MODULE [module URL in Github]
git fetch MODULE
after the above steps, when I do git remote -v it is displaying two remotes. One for PROJECT (origin) and one for MODULE.
After these steps, I am not sure what to do next in order to achieve my objective. Is it even possible?
I tried git merge MODULE/master --allow-unrelated-histories but it is adding my MODULE code into my PROJECT which I don't want.
Could someone point me in the right direction?
Thanks.
It would be easier to use git submodule for that kind of use.
Your parent repository would keep a reference on your MODULE repository in a MODULE subfolder, but any change done on that subfolder can be pushed directly to the remote MODULE repository.
cd /path/to/repo
git submodule add [module URL]
cd module
# work on module, add, push, commit
cd ..
git add module
git commit -m "reference new module state"
The OP amira confirms in the comments:
Worked like a charm.
In the settings.gradle folder, don't forget to include the module and provide a path as described in "Android Studio - How to make modules inside a subdirectory?".
This question already has answers here:
Detach (move) subdirectory into separate Git repository
(26 answers)
Closed 5 years ago.
I've made a 2-module project where one module is completely denoted to a library that I've made and I'm accessing that library from the other module(which contains the MainActivity.java) of the project. Now I want to push only my library to the GitHub so that anyone can use it for their need. I know how to push the entire project to GitHub but How can I extract the library ( module ) from the project and push only that. Thanks in Advance!
Based on my understanding, your root project is already versioned under git. If so then to version your library module as a separate git repo and also use it within other git repo projects, then you need to use git-submodule. The module will be pushed as a separate Android Project. Once that is done, you'll add the library to your app project by using git-submodule and configuring the settings.gradle to include the library module for compiling. And finally, add a dependency in your app build.gradle file to include the library in the app compilation.
This is so simple, maybe I misunderstand your need
git add <modulename.extension>
git commit -m "added single module"
git push origin master
I am trying to convert my existing application into a number of modules.
Is it possible for me to have each module pointing to a git repository so I can grant access to people accordingly?
So my structure is like this
APP --> Git 1
Module 1 --> Git 2
Module 2 --> Git 3
...
Is this possible for me to do with an android studio project?
The idea is for me to be able to give different developers different modules and not let them access other modules. I have never used git this extensively so dont really know how this works
Please help
Nikhil
Yes, Android studio supports multiple git repos.
you will have something like:
Repositories:
Repo 1 -> master
Repo 2 -> feature/branch-name
in AS Select VCS, VCS popup and import or check out repo. Or you can create new repo in your folder and and independently in subfolders.
I have a MainApp which refers to 2 other library projects. All projects are on different SVN servers.
The way I have been working on Eclipse ADT(not using Maven, which is not the good way) is that I imported all library projects one by one and then the MainApp - all within the same workspace. This way the library projects were easily referenced through project.properties ; because they used relative path of library projects. This also meant that I had to update all projects independently and no one-click project update was possible.
So I tried moving to Android Studio/Gradle build system. If I export the gradle files from my local workspace and then import project into AS, it finds all library projects and shows them up as modules in AS. The problem is that I cannot use SVN client in AS to work on my project - as AS assumes everything to be there on my local machine (and not as a SVN codebase)
The other approach I took was to import the build.gradle file for MainApp directly from SVN. This approach does not import the library projects, because, of course the MainApp does not know about the SVN URLs of the library projects.
How should I go around solving this problem, where I don't need to use another SVN client to play around my code ? And use absolute URLs for all library projects ?
Depending on your exact needs, there are several different solutions:
Publish library projects to a local or remote Maven repository (e.g. via their Gradle builds), and declare artifact dependencies on them in MainApp's build. Publishing can be automated by having CI builds for the library projects.
Include library projects' SVN repositories in MainApp's SVN repository using SVN externals, and have a single multi-project Gradle build.
Use Prezi's Pride tool to create a single multi-project build that spans multiple SVN repositories.
It's also possible to attach another Gradle project to an AS project (see the + icon in the Gradle tool window), but I'm not sure if/how this solves the problem at hand.
I have an Android application under development which makes use of a separate library project of my own. These two projects are stored in separate Git repositories. The application project references the library project by means of the .gitmodules file.
I'm now trying to work on both of these projects together (the application and the library) on a new machine. I cloned the application project, which resulted also in the library project being automatically cloned into my ~/git/ directory as well. So far so good.
I notice also that in Eclipse Package Explorer, the library project root has a commit hash within brackets (e.g. [MyLibraryName 0123ABC]). This presumably means that the library clone is from a certain commit point, and I understand that I could update this (i.e pull in the latest commits for this library) using git submodule foreach git pull.
Question is, what is the best way for me to continue separately developing the library project now? I tried to modify a file and stage it, but when using Team->commit, the dialogue didn't list the modified file. I assume this might be something to do with it being a submodule, pointing at a particular commit.
Should I clone my library project again, completely separately into a different subdirectory, and import as a separate project into Eclipse in order for me to do work on that library?
Having read various other SO questions, it seems apparent that there's no elegant solution for this. The steps I eventually took to solve this are:
Assuming not done so already, clone the application repository that makes use of submodules. Import all projects into Eclipse workspace, including the submodule repository (or repositories). Note that the submodule repository is a repository within the main application repository, and it's not on a particular branch; it's a reference to a particular commit (detached head).
In the Package Explorer, rename the submodule project that was imported. I gave it a name that relates to the application repo it's inside of. For instance, for an application project called ABCD, rename it from SomeLibrary to SomeLibrary_ABCD.
Next, clone the library separately from its own Git repository. Now, the point of renaming the submodule project is that it's now possible to import the Eclipse project from the standalone clone of the library repository, without Eclipse giving the "Some or all projects can not be imported because they already exist in the workspace" error.
Having done this, we have SomeLibrary_ABCD project which is not on a branch but points to a particular commit, and is a submodule of project ABCD. That submodule is updated using git submodule foreach git pull. Then, we have project SomeLibrary, which is on a branch (e.g. master).
My planned workflow is to locally switch the application project to point at my 'standalone' project of the library instead of the submodule version when I want to do development on the library. I then commit changes to SomeLibrary.
Any better suggestions than this (or corrections to anything I've stated) would be appreciated - but for now this is my own answer to the problem.