Since Android Studio 2.2 and up to 3.0, new projects are created with this gitignore file:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
For older project format, add this section to your gitignore file:
/*/out
/*/*/build
/*/*/production
*.iws
*.ipr
*~
*.swp
This file should be located in the project's root folder and not inside the project's module folder.