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?

  • Need to handle git-submodules in git-archive
  • Can't add git submodule when specified as a relative path
  • Managing Internal Shared Libraries with Git and Nuget
  • How to make git ignore changes to submodules by default
  • Jenkins with Git and XCode: cannot pull sub-sub-module?
  • Can I add a git release as a submodule?
  • Git submodules vs subtrees vs branches - how to choose the right one in a directory structure
  • Git remembers submodule's remote and history even after removing it
  • 3 Solutions collect form web for “Accessing git submodule in Android Studio”

    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.

    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.

    I wasn’t able to have any luck with the answers provided. As I kept searching the internet for a hint of help I stumbled across Joda-Time-Android so I removed the original Joda-Time submodule and tried again with the new. It works! It added itself to my project and it’s ready to rock!

    During the time I was still troubleshooting the original issue Joda-Time doesn’t include a build.gradle file but Joda-Time-Android does – I think that was the problem.

    Git Baby is a git and github fan, let's start git clone.