Best Practices for adding .gitignore file to Android projects

These tutorials talk about which files in the android project are committed and which files are not ignored in a git repository.

Android application gitignore file

Gitignore is a text file that contains a list of files or patterns that are excluded while committing an android project.

Following is a list of files and patterns for git ignore files

java files are compiled into class files, so class files are not required to commit to the repository

# Java class files
*.class

a lot of temporary files are generated.

# generated files
bin/
gen/

Gradle local files are not required, and the build folder contains the build output of a project

# Ignore Gradle files
.gradle/
build/

Configuration files like .iws, .ipr , .iml, and local.properties can be excluded

# configuration
.iws
.ipr
.iml
local.properties

Build generated package files

The following generate package files are added.

# built generated package files
*.apk
*.ap_

Dalvik VM files

# the Dalvik VM files
*.dex

log files

*.log

For key store files

*.jks

Android projects open in either Android studio as well as Intelli IDEA.

These IDE-related files can be ignored.

# Android Studio / IntelliJ IDEA
*.iws
.idea/libraries
.idea/tasks.xml
.idea/vcs.xml
.idea/workspace.xml
/out/

Operation System-specific files

# OS temporary files
.DS_Store
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Android app sample gitignore file example

Every android application contains gitignore file.

Here is a sample example file.

# Crash log files
hs_err_pid*

# Java class files
*.class

# Ignore Gradle files
.gradle/
build/

# generated files
bin/
gen/

# configuration
.iws
.ipr
.iml
local.properties

# built generated package files
*.apk
*.ap_
# Android Studio / IntelliJ IDEA
*.iws
.idea/libraries
.idea/tasks.xml
.idea/vcs.xml
.idea/workspace.xml
/out/

# OS temporary files
.DS_Store
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# For eclipse Eclipse
proguard/

# Android Patch ###
gen-external-apklibs

# Packaging files
*.jar
*.war
*.ear