Android Studio gitignore to avoid useless files

Create a perfect Android Studio .gitignore file is sometimes tedious, so I have gathered some information on the Internet, mainly on StackOverflow, I made some experiments with my sample project over and over and finally I obtained a perfect Android Studio .gitignore file.

Usually, I create my project inside a parent folder which I initialize as my Git repository.

So, for example, this is a sample structure (folders are bolded):


  • .git
  • AndroidShowCase
    • .gradle
    • .idea
    • app
    • build
    • gradle
    • .gitignore
    • AndroidShowcase.iml
    • build.gradle
    • gradlew
    • gradlew.bat
    • settings.gradle
  • .gitignore

I use the following as content for the .gitignore file in the AndroidShowcaseRepository folder

# Built application files

# Files for the Dalvik VM

# Java class files

# Generated files

# Gradle files

# Local configuration file (sdk path, etc)

# Proguard folder generated by Eclipse

# Log Files

and the following as content for the .gitignore file in the AndroidShowcase folder


Using these two .gitignore files (and the default ones created by Android Studio inside the app folder and into other folders you could have) you will likely save only the necessary source code to your repository and not files which could be generated by Android Studio itself.

Check w3ma showcase repository for the complete source code and for more explanation!