Android Studio .gitignore Configuration
Proper .gitignore for Android Studio and Gradle-based Android projects. Covers build output, local.properties, APK files, and generated source code.
Detailed Explanation
Android projects built with Android Studio and Gradle generate extensive build artifacts, IDE metadata, and local configuration files. A correct .gitignore prevents repository bloat and avoids machine-specific path issues.
Gradle build output:
build/— Every module's compiled output, generated resources, and packaged APK/AAB files. Ignored at all levels: root/build/and module-level*/build/..gradle/— Gradle's per-project cache, including task history and file snapshots.
Local configuration:
local.properties— Containssdk.dir=/path/to/Android/Sdk. This path is different on every developer's machine (macOS vs Linux vs Windows). It is generated by Android Studio on project import. Never commit this file.*.propertiesexcludinggradle.properties— Some property files contain signing credentials. Be selective about which.propertiesfiles you commit.
Android Studio / IntelliJ patterns:
.idea/— IDE configuration (see IntelliJ section for detailed breakdown).*.iml— Module files with local SDK and dependency paths..idea/workspace.xml— User-specific workspace state that changes every session.
Build artifacts:
*.apk— Android application packages. These should be built by CI and distributed via the Play Store or Firebase App Distribution.*.aab— Android App Bundles (the modern distribution format required by Google Play).*.ap_— Packaged resource files generated during the build.*.dex— Compiled Dalvik bytecode for the Android runtime.
Signing and security:
*.jksand*.keystore— Signing keystores containing private keys. Git is NOT the right place for these. Store keystores in a secure vault (1Password, HashiCorp Vault, or your CI provider's secrets).signing.properties— Keystore passwords and alias configurations.
What to commit: gradle/wrapper/gradle-wrapper.jar, gradle/wrapper/gradle-wrapper.properties, gradlew, gradlew.bat, and gradle.properties (with non-sensitive JVM arguments). These ensure everyone uses the same Gradle version without a global installation.
Use Case
An Android team onboarding new developers finds that local.properties and build directories keep being committed, causing SDK path errors on different operating systems.