Skip to content
vast-cow's blog
Go back

How to Think About `.gitignore` for Android Studio and a Standard Practical Setup

Edit page

When developing Android apps in Android Studio (Gradle / Kotlin-based), many developers struggle at least once with how to write a .gitignore. In practice, discussions and real-world knowledge online have largely converged, and the way of thinking about “what to exclude from Git” is fairly consistent.

In this article, we organize widely referenced official templates and practical discussion points, and succinctly summarize a safe, easy-to-adopt .gitignore as a starting point, along with areas where opinions tend to differ.

Basic Policy for an Android .gitignore

A .gitignore for Android Studio is generally structured around excluding the following four categories:

As a starting point for this way of thinking, many people refer to GitHub’s official Android.gitignore. On Stack Overflow and in Japanese articles as well, it’s common to see advice like “start with this as a base.” (GitHub)

Official References Commonly Used as Standards

GitHub’s Android.gitignore

The Android.gitignore published by GitHub includes items such as the following (summary):

This aligns with the overall philosophy of GitHub’s gitignore repository as a whole, and the stance of “base your setup on the official template” is widely supported. (GitHub)

JetBrains’ (IntelliJ / Android Studio) Official View

On the other hand, opinions differ on how to handle the .idea directory.

In JetBrains’ official guide (updated 2025-11-26), the guidance is summarized as follows:

In other words, from JetBrains’ perspective, “ignoring .idea entirely is not necessarily correct,” but they also acknowledge practical flexibility for Gradle-based Android projects. (JetBrains)

Notes When Using Kotlin

The Kotlin Gradle Plugin generates a .kotlin/ directory at the project root. The official documentation explicitly states that this should not be committed.

Therefore, for projects using Kotlin, adding .kotlin/ to .gitignore is standard practice. (Kotlin)

Point of Divergence ①: What to Do with .idea/

In real-world usage, approaches generally fall into two categories:

A) Ignore .idea/ Entirely

Developers who believe “Gradle defines the source of truth for project structure, and IDE settings vary greatly by individual” often choose this simple approach. (Qiita)

B) Keep Only Shareable Parts of .idea/

When Android Studio is used as the team’s standard IDE, this compromise approach is sometimes chosen. (GitHub)

Point of Divergence ②: google-services.json

google-services.json does not contain secret keys themselves, but how to handle it depends on policy.

GitHub’s Android.gitignore includes it in the ignore list by default. (GitHub)

A Safe, Practical .gitignore Recommendation

Below is a configuration that:

and is easy to adopt as an initial setup.

# ===== OS / editor =====
.DS_Store
Thumbs.db
*.swp
*.swo
 
# ===== Gradle / Kotlin =====
.gradle/
.kotlin/
build/
local.properties
 
# ===== Android Studio / IntelliJ =====
*.iml
.idea/
*.ipr
*.iws
out/
 
# ===== Android build outputs =====
*.apk
*.aab
output-metadata.json
 
# ===== Android Studio generated =====
captures/
.externalNativeBuild/
.cxx/
 
# ===== Profiling =====
*.hprof
 
# ===== Signing / secrets =====
*.jks
*.keystore
keystore.properties
signing.properties
 
# ===== Google Services (decide by policy) =====
# google-services.json

This setup is considered a safe choice in many teams because it “keeps diffs under control and avoids unnecessary conflicts.” (GitHub)

A Compromise When You Want to Share .idea/

Another approach is to avoid ignoring .idea entirely, and instead exclude only user-specific files and generated artifacts.

.idea/**/workspace.xml
.idea/**/usage.statistics.xml
.idea/**/shelf/
 
.idea/**/tasks.xml
.idea/**/dictionaries/
 
.idea/**/modules.xml
.idea/**/gradle.xml
.idea/**/libraries/
 
*.iml

This is a realistic compromise that combines JetBrains’ official policy with the realities of Gradle projects. (JetBrains)

Convenient Ways to Generate .gitignore

If you want to specify multiple OSes and tools at once, gitignore.io (provided by Toptal) is convenient.

curl -L "https://www.toptal.com/developers/gitignore/api/android,androidstudio,gradle,kotlin,macos,windows,linux" > .gitignore

(Toptal)

Common Pitfalls


Edit page
Share this post:

Comments


Previous Post
A Bookmarklet to Copy Codex Assistant Replies and PR Messages to Your Clipboard
Next Post
For Google TV (Android TV OS): Launching a Minimal App with Android Studio + Kotlin