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.
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?".
I was using a project as module dependency in Android Studio. I no longer now need it. So I removed the dependency from build.gradle file and then committed and pushed it. When i take a fresh check out using git in Android Studio, i am able to see that module, even though that is not being used by my project. If i check on the git site, the folder is still there. I think i need to delete it from the cache of the git which maintain the history of this. But I do not know the commands to run in the Android studio terminal to completely remove it from git respository.
Project Structure
Project
|
-app
-build.gradle(removed dependency of module 1)
-Module1
-Module2
-module3
-settings.gradle(removed module1)
Want to remove module1 from the git. Please let me know the commands.
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/
I am looking a source code repository and it only contains code for an Android project i.e. src/main/java/com/.. and no project definition files such as .idea, .iml ,.ipr, .iws - These files are included in the .gitignore file.
There are no files relating to an Android Studio project at all so I cannot open in the IDE. It has been set up for Maven so I can build that way. If I want to run/debug/alter this project what do I do?
Why would somebody exclude all IDE project files?
It's easy, the repository/source code owner don't commit the project files because the source code must be independent of the IDE used by people. The projects files of Eclipse are different from one of IntelliJ.
You can clone or download the source code and even not use any IDE. Some poeple prefer working with editors like Emacs or Vi and build the project using the command line.
There are many ways to create android projects with Android Studio and Eclipse being the main two.
If the author had to maintain project files it would add considerably to the work required as IDEs etc get updates at different rates.
This way the code is "portable" between IDEs and the author can focus on just supporting his work rather than all of the combinations of IDE/Operating Systems.
My Solution
I am posting solution here as I cannot yet answer my own question.
So, I the solution was in the Maven definition. My codebase was an SDK consisting of numerous libraries and sample apps. Each component had a POM.xml and was all contained using a Parent POM.
All I did was import the Parent POM into Android Studio. Once triggered Android Studio would create its own project files using the POM definitions for each component. All the modules were available in one instance and it built and ran instantly. It was truly beautiful :)
Steps: Import Project -> Select directory containing POM.xml -> "Import project from external model" -> Maven -> Next -> continue to create project.
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.