Not working properly .gitignore when versioning an Android project

4

I still can not have a .gitignore file that can help my code versioned in git for an Android project, if I modify a class or something very simple modifications are made in unnecessary files like tests.

Annex my .gitignore too.

*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/dictionaries
.idea/libraries

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

Thank you.

    
asked by Rogelio Sanchez 26.10.2017 в 17:11
source

3 answers

4

Review the documentation , where you specify:

  

A file gitignore intentionally specifies files without   tracking (untracked files) that git should ignore. Keep in mind that all gitignore files really only refer to files that have not yet been tracked by git

Therefore, what is defined within .gitignore applies to files without follow-up, in your case the files that I see mainly are those that are within the directories /build are already marked for tracking.

To take the changes made in the .gitignore do the following:

Perform committing pending changes and remove modified index files:

git rm --cached -r .

save changes:

git add .

and commit:

git commit -m ".gitignore funcionando!"

Reviewing your file .gitignore , I can suggest some changes:

  • *.iml change by **/*.iml to search all directories for files with the .iml extension

  • .gradle by .gradle/ correctly specifies a directory.

  • If you specify /build , you do not have to specify the files *.dex and *.class , since they are inside this directory, the same for the directories bin/ gen/ (in android is /generated ) and out/ (in android is /outputs ), it is not necessary to specify them.

Documentation link

    
answered by 26.10.2017 / 18:52
source
3

Adding the .gitignore file to the directory does not mean that you will ignore it that way. You have to run the following commands so that gitignore recognizes the files that should not be tracked. Remember to commit to the files you have currently or you will lose the changes in those files

git rm -r --cached .
git add .
git commit -m "Reparados archivos no trackeados"
    
answered by 26.10.2017 в 18:18
2

Your problem seems to be that the sample-core / build / folder is being versioned

To solve this, in addition to the .gitnore file that you have in the root of your project, you should add an additional .gitignore file within your sample-core folder. The file should have the following content:

/build

As an additional fact, when you create a new project with Android Studio, the IDE automatically generates these two .gitignore files: one in the root of the project and another in the module. Here more information about the structure of projects on Android.

    
answered by 26.10.2017 в 17:39