How to push submodule to github using android studio? - android

I cloned an android project from github. I made changes after cloning and pushed it to the main repository from android studio. Everything worked fine but when I add an external library in my project I can't push it. I think its a sub module. Could anyone tell me how to push external library as a sub module from android studio?

After searching internet I found a simple way to do it. To add a sub-module we need to run this command
git submodule add LIBRARY_URL
and to init the sub module locally
git submodule update --init --recursive

If it is a submodule, you should be able to list the gitlink entry, special mode 160000
$ git ls-tree HEAD mysubmodule
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398 mysubmodule
It should also be recorded in your main repo/.gitmodules file.
In that case, all you need to do is add and commit that entry, and push it.
If it is not, then remove that folder, and add it again as a submodule through command-line (instead of Eclipse/Egit)
git submodule add /url/of/library/repo mysubmodule
git add mysubmodule # no trailing / here)
git commit -m "Add a submodule"
git push toAndroidRemoteRepo

Related

Two unmerged repositories inside one project

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?".

how to add a git non-android library project as a sub module, to android project

I am working on project were I have to initialize this repo https://github.com/livekit/protocol as submodule in my android project. How can I achieve this?
First clone the Android project into your local system.
git clone https://github.com/username/repo-name
Then using the git submodule add command, add the URL of the submodule
git submodule add https://github.com/livekit/protocol
Then execute the following commands:
git add .
git commit -m "Commit message"
git push origin master
In the last command replace masterwith the name of branch you are working with.

Git/Android - Cannot commit submodule in assets folder

I'm trying to use a submodule in my Android application, and while I was able to add the submodule successful, when trying to commit a change to use the latest version of that submodule, it throws an error.
The submodule is a simple repo that just contains json data that multiple applications are using.
I navigated to the assets directory within my Android app, and added the submodule like normal and gave it an alias "database"
git submodule add https://github.com/.... database
Now, that works but when I updated the submodule, I'm unable to commit the change within my main repo saying "use the the latest version of that submodule"
my_app\src\main\assets\database
"-" Subproject commit 3521bd386c99....
"+" Subproject commit d135dc8cd5b0....
"d135dc8cd5b0...." being the latest version of that submodule.
If I try to commit that change, it'll throw this error.
Could not commit submodules:
my_app/src/main/assets/database
Add them as submodules from Git Shell or remove their .git folders
and add them as a regular directories instead.
But I already added it as a submodule through the Git Shell. Any idea on how to fix this?
Thanks.
You should be able to commit the updated submodule if you commit it all by itself using its directory path:
git commit my_app/src/main/assets/database -m "Updated database submodule"
You should then be able to commit all the other changes you have made to your repository:
git commit -m "Improved flux capacitor code"

Cloning a subdirectory of a repository off GitHub using Android Studio

I was wondering whether it is possible to clone a subdirectory of a repository off GitHub using Android Studio? Usually when you clone a repository, you go "Check out project from Version Control" --> GitHub --> then you get something like this
However, for example, I would like to clone this subrepository as I would like to build the project and put it in my emulator. This address is https://github.com/hmkcode/Android/tree/master/android-material-design-appcompat.
I have tried to guess https://github.com/hmkcode/Android.git might have becomehttps://github.com/hmkcode/Android/android-material-design-appcompat.git, but this did not work.
Is it possible to clone this subrepository as I dont want the rest of the repository. I dont want to have to clone the whole thing and try to piece together the sub project.
This is not a "subrepo": it is just a subdirectory, and git reasons at the repo level.
You could use sparse checkout though, but it is not supported directly by Android studio. You would have to prepare your local repo:
mkdir hacker-scripts
cd hacker-scripts
git init .
git config core.sparseCheckout true
echo 'android-material-design-appcompat/' > .git/info/sparse-checkout
git remote add -f origin https://...
git pull origin master

How to include project on git into new android project

How I can include existing project into my android app.
following is the one i want to use:
https://github.com/dhis2/dhis2-android-sdk
You should be able to add your project as a submodule of your android app repo.
See for instance this question:
cd C:\Users\USER\AndroidStudioProjects\ProjectName
git submodule add https://github.com/dhis2/dhis2-android-sdk
file structure:
ProjectName
app
dhis2-android-sdk

Categories

Resources