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

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"

Related

How to gitignore a particular Java file or any folder or any XML file in Android project?

I have a project in Bitbucket and I want to give access to one of my intern. I want to ignore certain Java files and certain file inside debug folder.
I have tried using the way, adding this line in my gitignore file:
/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.class
However, this didn't work out.
I also tried:
/NewActivity.class
didn't work out too.
How can I do that?
You can not ignore those files that you have previously committed, for that you have to remove those files from your git.
To do that first go to your file directory.
Now type this command to remove the file from your git.
git rm --cached [filename]
Now the file has been removed from your branch, and now
you have to add the file name in your .gitignore file.
filename.java (Remember that the activity extension should be in java.)
After that, add the files to the branch and then commit them. Then
finally, push and you will see the files are ignored.
Please mind, that the path of files you want to ignore with a .gitignore file are relative to the path of your .gitignore file in your repo.
so:
/NewActivity.class
means: ignore the file NewActivity.class in the same directory as .gitignore and not in subdirectories
NewActivity.class
means: ignore the file NewActivity.class in the same directory as .gitignore and in all subdirectories
If you want to use:
/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.class
then your .gitignore file has to be located in a parent direcory of app, which has to be part of your repository of course.
I think the extension should be .java instead of .class.
So instead of this
/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.class
It should be this
/app/src/main/java/com/example/amanv/emulatordetection/NewActivity.java

Should I version app/build files in Android Studio?

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

Gitignore not ignoring some build files in Android library

I have an Android library and for some reason, the files and folders I have specified in my .gitignore are not being ignored.
I have tried modifying my .gitignore and also following these steps, but this doesn't change anything.
Here is my top-level .gitignore (which can also be found on the GitHub repo):
# Gradle files
.gradle/
build/
*/build/
# Local configuration file (sdk path, etc)
local.properties
# IntelliJ
*.iml
/.idea
The module with the build folder that isn't being ignored has the following .gitignore:
/build/
I'm not sure why the build directory isn't being ignored, as it is being ignored in my sample app module, and in the top-level directory.
Also, I did commit changes to some files in the build directory when I updated versions of my library, if that's important.
This answer on Stack Overflow helped me solve my issue.
Here is part of that answer:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
You must remove the first / in your lower level gitignore before build, it will work then.
Also, in top level, you only need this: build/ and then no lower level gitignore will be needed.
Add .gitignore file in your project, and set below lines:
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/build
/captures
.externalNativeBuild
.idea
In my case the .gitignore file was placed inside app directory instead of being in root of project directory.
I figured this out by:
Open Project View in Android Studio
Right-click on build folder
Select Git
Add to .gitignore

Unable to add a file to gitignore in Android Studio

I want to add a file named Credentials to .gitignore, so here's how I did, I added the following line to .gitignore file which is in app directory:
/src/main/java/my/package/name/utils/Credentials.java
But it still shows up in git status.
Quoting man gitignore :
A gitignore file specifies intentionally untracked files that Git
should ignore. Files already tracked by Git are not affected
If the file that you're looking to have ignored by git is already a file being tracked, you'll have to git rm --cached it first.
For more info: https://git-scm.com/docs/gitignore

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