What Should Be in My .Gitignore for an Android Studio Project?

Better Stack Team
Updated on August 12, 2024

For an Android Studio project, the .gitignore file should exclude files and directories that are specific to the build process, IDE configurations, and other environment-specific files that don't need to be shared with others. Below is a typical .gitignore file for an Android Studio project.

Example .gitignore for an Android Studio Project

 
# Gradle files
.gradle/
build/

# Local configuration files
local.properties

# Android Studio and IntelliJ IDEA files
.idea/
*.iml
*.iws
*.ipr

# Android Studio cache
.idea/caches/
.idea/libraries/
.idea/modules.xml
.idea/workspace.xml
.idea/gradle.xml
.idea/usage.statistics.xml
.idea/dictionaries/
.idea/httpRequests/

# Keystore files
*.jks
*.keystore

# Log files
*.log

# OS-specific files
.DS_Store
Thumbs.db

# Build directories
app/build/
*/build/

# Proguard configuration files
proguard-rules.pro

# Miscellaneous
*.apk
*.ap_
*.dex
*.class

# Android NDK
ndkBuild/
local.properties

Explanation of Entries

  • Gradle Files:
    • .gradle/ - Gradle cache directory.
    • build/ - Output directory for build artifacts.
  • Local Configuration Files:
    • local.properties - Local configuration that contains sensitive information (e.g., SDK path) specific to a user's environment.
  • Android Studio and IntelliJ IDEA Files:
    • .idea/ - Directory containing IDE-specific settings and workspace configurations.
    • .iml, .iws, .ipr - IntelliJ IDEA project files.
  • Android Studio Cache:
    • .idea/caches/, .idea/libraries/ - Caches and libraries managed by Android Studio.
  • Keystore Files:
    • .jks, .keystore - Keystore files used for signing your application. These files should be kept private.
  • Log Files:
    • .log - Log files generated by the build process or runtime.
  • OS-Specific Files:
    • .DS_Store (macOS) - Finder metadata.
    • Thumbs.db (Windows) - Thumbnail cache.
  • Build Directories:
    • app/build/, /build/ - Build artifacts for different modules.
  • Proguard Configuration Files:
    • proguard-rules.pro - Configuration file for Proguard (used for code obfuscation).
  • Miscellaneous:
    • .apk, .ap_, .dex, .class - Compiled APK files, dex files, and class files that are generated during the build process.
  • Android NDK:
    • ndkBuild/ - Directory for NDK builds (if applicable).

Additional Notes

  1. Sensitive Information: Avoid committing sensitive information like API keys or credentials. If you have any sensitive data, consider using environment variables or configuration management tools.
  2. Custom Files: Adjust the .gitignore based on any custom configurations or additional files specific to your project's setup.
  3. IDE-Specific Settings: If you use other IDEs or editors in addition to Android Studio, you may need to adjust the .gitignore to exclude their respective configuration files.

Summary

A well-configured .gitignore for an Android Studio project helps to keep your Git repository clean by excluding files that are specific to the build process, IDE configurations, and local environment settings. This ensures that only relevant source code and configuration files are tracked in version control.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github