Should I version app/build files in Android Studio? - android

I'm new to Git and Android development and I could not find an answer to this question.
When I build a project in Android Studio a lot of files are created in the folder app/build.
I guess I don't need that files, but before ignoring them in the .gitignore, I would like to be sure to not mess my repo since from the first commit :D
I checked this question, but I cannot see in the example .gitignore the folder app/build.
Should I add it to my .gitignore?
P.S. I'm using Android Studio 2.2.3, if relevant

I guess I don't need that files, but before ignoring them in the .gitignore I would like to be sure to not mess my repo since from the first commit :D
You don't need build files in your repo.
Usually .gitignore file contains /build.
I checked this question but I cannot see in the example .gitignore the folder app/build.
You can place another one .gitignore file to app directory, the content of this file also contains /build.
/project
.gitignore
/app
.gitignore

If I copy/past the example .gitignore (which contains build/ ) in the app/ folder, build files are not ignored.
That would be because those files are already tracked.
Try:
cd app
git rm --cached -r build/
git add .
git commit -m "record build content deletion"
git push
Then app/build will be ignored.

Have a look at gitignore.io for generating gitignore files

Related

About the .gitignore question, .cxx folder in the Android project

Here's a question about Git, .gitignore on Android!
======================================================
Q1) What files are created in myproject/app/.cxx?
I am using ndk, jni in android project.
It seems that the files related to this are being automatically changed in myproject/app/.cxx.
When I try to branch move, the files in this folder are changed, so I have a problem that I have to commit.
So I want to add that directory to .gitignore,
I don't know exactly what that directory is, so I'm wondering if I can add it to .gitignore
======================================================
Q2) I have multiple .gitignore files.
If I add that directory (myproject/app/.cxx) to .gitignore,
There is also a .gitignore file in the "myproject" folder,
There is also a .gitignore file in the "myproject/app" folder.
Should i edit .gitignore in "myproject/app"??
As to answer your second question, You need to have only one .gitignore file at the root of the project folder.
As to answer your first question, all the .cxx files must be ignored. You can have the below line in .gitignore file.
** /.cxx
If you have already tracked this file, use the below commands after adding the above line in .gitignore file
git rm --cached . (Don't forget the dot at the end)
git add .
git commit -m "Commit-message"

Commit Folder Android Studio Project

Not all folder in project uploaded to github as default. Is it ok?
such folder build not uploading to git as default. any reference about it? should I leave it or including folder build too?
How to do that?
Thank you
By default build/ is part of .gitignore that is why it's not been uploaded on remote. This is perfectly fine.
Even if you wish to include it into remote repository.
git rm --cached .
git add -A
git commit -m "Message of your choice"
git push origin branch_name
Android projects now are created with a .gitignore file. gitignore specifies intentionally untracked files to ignore. So one of the files that are specified in gitignore is the build folder. Therefore when you commit, it doesn't get uploaded to git as default. You should leave it alone but if you want to, you can simply remove the build folder specified in .gitignore.
You can also look at this post as well. Hope this helps!

Can't Remove git Sub-Module

I am fairly new to git and had not really utilized the command-line interface until recently. I was trying to start a new private repository on github using Android Studio and made a mistake. I ran the command:
git remote add origin [github.com/location]in two places, one of which was the root folder of the project, and one of which was subfolder containing the java class files. When I tried to add and commit all the files, it wouldn't include the subfolder, giving me the error: fatal: Pathspec 'file' is in submodule 'app/src/...' Before thinking through what I was doing, I tried removing the .git folder from the subfolder. There is no .gitmodules file in the .git folder in the root project folder, so there are no submodules to remove. I'm not sure if this is enough information to go off of so I'm sorry in advance if this sounds vague, but I was hoping someone could help me clear whatever is causing this so I can add this subfolder to the main project and commit it. Thank you!
FIXED:
I figured out that I needed to remove the subfolder and re-add it thusly:
git rm --cached dirname
git add dirname
I also had to get rid of the index.lock file in the base project .git folder in order to do this.
Did you check on the github repo if there is no conflict?
Do you try to commit locally or commit and push?
Did you try to clone the project on a another location?
If you use Windows or Mac, I have a nice tool for git repository Source Tree

First push of Android Studio in Git

Question partially related with gitignore file.
Now when you create an Android project, Android Studio creates .gitignore with your project.
BUT it does not help, these files would be ignored if your code is already in git repository and ignored files ARE NOT already pushed.
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
Now i create a project, Android Studio creates tons of other files including , .idea .IML and so on and i have no idea how can i clean these irrelevant files and folder so i can push clean code to he repository.
Should i do this manually
if ignored files are already in your repository then you should cut them to a new folder outside repository (ex. desktop) then commit deleted files and then turn them back to repository ! this time they will not been tracked by git because they are in your .gitignore file
You can use git rm to untrack files without removing them if you have access to a terminal with git.

eclipse android gitignore for project.properties file

I m collaborating with another developer over git. Our setup environments are different. To avoid adding the correct sdk and other libraries I decided to include this line in .gitignore
#eclipse
project.properties
but in the initial commits my project.properties file was pushed onto the repository. I thought updating the .gitignore file would take care of this problem on the other developers machine. But every time he pull the repository he has to update the project with the path of his sdk and library to be able to run the code.
If you want to ignore a file within your git repository that was already tracked by the system, you have to delete the file from the repository cache. After deleting the file, you can add the ignore rule to your .gitignore file and it will be ignored by the repository.
First: Delete the file from the repository cache
git rm --cached path/file
Second: Add the ignore rule to your .gitignore file
path/filename
Third: Commit the updated .gitignore file
git add file
git commit -m "Updated .gitignore rule"
git push
found here:
http://www.wegtam.net/article/add-file-gitignore-was-already-tracked

Categories

Resources