Search code examples
androidgitandroid-studiogithubgitignore

How to make sure .gitignore works for multiple Android projects in the same repository


My problem is similar to the one outlined in this post, but the solution did not help. I essentially have one Github repository with a whole bunch of different folders/directories that each contain a separate Android project.

The structure of one such project looks like MyTeamRepo -> MyAndroidProject -> app

Normally if it was just a single Android project, throwing the .gitignore in the /gradle directory would work, but it's not working out in my case.

Here's what's currently in my .gitignore:

# Built application files
*.apk
*.ap_
*.aab

# 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/misc.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches


# Android Studio 3 in .gitignore file.
.idea/caches/build_file_checksums.ser
.idea/modules.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# 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
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
lint/reports/

My problem is I still keep having these .idea and .gradle files popping up everywhere within the subfolders every time I make any changes to the Android project, causing all sorts of merge conflicts when I try to pull changes from Github.

I also think part of the problem is that the .idea had previously been committed to Github and now I am always tracking it.

What steps do I need to take to completely clean my repository and to make sure the .gitignore is doing its job?


Solution

  • If you want to ignore a file anywhere in the tree use something like

    **/.idea/modules.xml
    

    and no matter where the .idea directory is that the modules.xml file will be ignored.