Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing git submodule in Android Studio

I'm just starting out using source control for my own project, and now I want to add Joda-Time. I want to add it as a submodule so I went into the terminal and executed:

git submodule add https://github.com/JodaOrg/joda-time.git

and it downloaded all the files successfully. Then I ran:

git submodule init

And got nothing back.

git submodule status

returns

b9fe534c7f5876eced6494a6d6c1deaf2528a579 joda-time (v2.7-17-gb9fe534)

I checked my projects root directory and I see the new joda-time directory and it's source. But now how do I access the library in my project? Did I miss a step?

like image 397
bwoogie Avatar asked Apr 16 '15 16:04

bwoogie


People also ask

What is submodule in Android?

In this article, you'll learn how maintain a remote sub-module in android projects. A remote sub-module is an android library module hosted on git as a repository that can be added as a sub-module to several projects. Along with that you'll also learn why we need a remote sub-module and how to create one.

How do you pull a submodule?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .

How do I run a git submodule?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.


2 Answers

Try with git submodule update --init. This will allow you to do git submodule init and git submodule update in one step. Note that you only need to add the --init option once.

Quoting from the doc:

update

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules.

On the other hand, git init by itself simply

copying submodule names and urls from [your] .gitmodules [file] to [your local] .git/config [folder].

Once you did this, you will notice that your submodule is in a DETACHED state. You can simply checkout any existing branch from there, say, git checkout master to checkout upstream master branch.

like image 78
ivan.sim Avatar answered Oct 09 '22 04:10

ivan.sim


You missed git submodule update. From the docs:

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules.

You can also do it with the --init option, which will do the git submodule init for you.

like image 36
Яois Avatar answered Oct 09 '22 03:10

Яois