Android Studio .gitignore template
The Android Studio template ignores the local properties file, module files, build output and native build directories, and picks specific files out of the editor folder.
At a glance
- Category
- IDE
- Patterns in this template
- 16 rules
- Directories ignored
- 4 of the 16 rules end in a slash, so they match directories only
- Also needs an OS template
- It already carries .DS_Store, but a full OS template is still worth adding.
- Typical companions
- Kotlin or Java, plus Gradle. The IDE rules are largely covered here.
In detail
local.properties is the rule that matters. It records the absolute path to the Android SDK on this machine, and often the NDK path too. Those paths differ on every developer's machine and between every operating system, so a committed copy causes a build failure with a confusing message about a missing SDK. It is also a place where signing configuration sometimes ends up, including a keystore password, which turns a nuisance into a leak.
This template takes a more surgical approach to the editor directory than the standalone IntelliJ one. Instead of ignoring .idea wholesale, it names specific files: caches, libraries, modules.xml, workspace.xml, navEditor.xml and assetWizardSettings.xml. Those are the machine specific ones, which leaves room for a team to track the shared code style and inspection profiles in the same directory.
/build and *.iml cover the Gradle output directory and the module descriptors. .gradle holds the build tool's own caches and daemon state. All three are regenerated, and the module files in particular are rewritten on every project sync. Tracking a module file therefore guarantees a conflict on any branch where somebody added a dependency, which is a slow way to learn what the rule was for.
.externalNativeBuild and .cxx are the working directories for native code built through the native build integration. They contain compiler output and generated build files keyed to the ABI and the toolchain installed locally. A project with no native code never sees either directory, which is why the rules are easy to overlook until the first build produces gigabytes nobody expected.
/captures is where the profiler saves recorded traces, and *.apk is the packaged application. output.json is the build output metadata file listing what was produced and with which version code, which is generated on every build. Profiler traces in particular are large and describe one run on one device, so they belong in an issue tracker attachment rather than in the repository.
Examples
*.iml
.gradle/
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build/
/captures
.externalNativeBuild/
.cxx/
*.apk
output.json16 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- local.properties can hold a keystore password as well as the SDK path. Treat a committed copy as a credential leak rather than a configuration mistake.
- The template ignores specific files under .idea rather than the whole directory, so a file the editor adds in a future version will not be covered until you add it.
- *.apk is ignored, but a release build's mapping file for deobfuscating crash reports is not, and that one is worth keeping somewhere retrievable.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Kotlin .gitignore template
The Kotlin template covers the same class and archive output as Java, plus the .kotlin session directory the newer compiler writes into the project root.
Gradle .gitignore template
Six rules covering the Gradle cache and build directories, with negations that keep the wrapper jar and properties tracked because a clone needs both.
IntelliJ IDEA .gitignore template
The IntelliJ template ignores the whole .idea directory and the module files, which is simpler than the alternative and loses some settings worth sharing.
macOS .gitignore template
Where .DS_Store actually comes from, why it appears in folders nobody edited, and what the rest of the macOS template covers on network and removable volumes.
Windows .gitignore template
What the Windows template covers: the thumbnail caches Explorer writes into image folders, the folder view settings file, and installer package extensions.
Linux .gitignore template
The shortest template in the collection. Five rules covering editor backup files, file manager settings, per volume trash and NFS silly rename files.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS