53

Which files in an Android project should be committed to a version control repository? Which files should not be committed?

Right now my .gitignore file consists of the following lines:

# Android generated files #
###########################
android.keystore
local.properties
bin/
gen/
libs/
obj/

# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db

# Eclipse generated files #
###########################
.settings/org.eclipse.jdt.core.prefs

Am I missing anything?

Eric
  • 1,182
  • 2
  • 15
  • 25

5 Answers5

40

GitHub maintains an official list of recommended .gitignore files at this public repository.

For Android you can find it here

Or just copy/paste :

# Built application files
*.apk
*.aar
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
#  Uncomment the following line in case you need and you don't have the release build type files in your app
# release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
.cxx/

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
Arjun Vyas
  • 409
  • 5
  • 14
mt0s
  • 5,781
  • 10
  • 42
  • 53
7

The general rule of thumb is to not commit any file that can be re-generated, into the repository. Having said that, you may want to add your project.properties file to .gitignore as well (if it exists).

Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
  • Doesn't the project.properties contain important project metadata. If you delete it you'll have trouble regenerating it. – Ricardo Gladwell Aug 19 '12 at 08:53
  • @RicardoGladwell You can regenerate your `project.properties` using the following command in your project main directory: `android update project --path . --target android-16` (or any other API level target) – Nilhcem Dec 06 '12 at 14:48
  • 2
    @Nilhcem that's a brittle, manual step that can easily be forgotten, you should commit your project.properties as part of your other source files. – Ricardo Gladwell Dec 06 '12 at 23:21
  • 1
    My rule is to not check in anything that is automatically created by the build procedure. If you can put "android update project..." in your Makefile (or equivalent), and it will be automatically created without problems any time it needs to be, then don't check it in. Otherwise, do check it in. – Edward Falk May 18 '13 at 00:21
  • 1
    Note also: some build artifacts should *also* be checked in if there are a significant number of developers who won't necessarily have the tools to generate them. For example, if not everybody has, or can get, yacc and lex, then I would check in the generated .c files. The same goes for documentation created via TEXINFO. This goes double for compile artifacts generated by proprietary or licensed tools. – Edward Falk May 18 '13 at 00:24
  • 4
    At the top of `project.properties` -- `"# This file must be checked in Version Control Systems."` -- This file is important especially if you use Android Libraries, it maintains what libraries you have and their locations. Typically these libraries should be included with the source. – Constantin Jul 05 '13 at 20:24
3

don't add bin folder and gen folder. They are not part of your sources they are generated. In future remember that you add only files necessary to build and run your project, and binary and generated files are not.

Yet if you're not using any tool like ivy or maven you may want your lib folder to present. Often when you use a library project, you also need to commit it

Orest
  • 1,857
  • 5
  • 19
  • 27
  • 2
    FYI, he's **not** committing either the `bin` or the `gen` folder. What you're seeing there is his `.gitignore` file. – Marvin Pinto Jan 15 '12 at 19:12
  • 1
    I haven't said he is doing that, i just noticed that it's the worst practice – Orest Jan 15 '12 at 19:22
  • I've had to deal with a vendor who checked in all the .o and .pyc files. Every time I did a build, "git status" would generate thousands of lines of "changed" files. – Edward Falk May 18 '13 at 00:26
0

As of Android Studio 2.2.2 (and was probably added well before this version) when you create a new project, Google add a default .gitignore file to the project for you with the following contents:

*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild

A little different from the above answers, as it also ignores the .idea folders, which tend to have a lot of files in them.

Xcalibur
  • 3,613
  • 2
  • 32
  • 26
0

Using darcs, one adds the tracked files explicitly, rather than excluding them with an ignore file. After creating the new android project, I recorded my initial commit with all .java, .xml, .gradle, .properties, and .webp files added, except for local.properties.

This command did that:

( fd .*.java & fd .*.xml & fd .*.gradle & fd .*.properties & fd .*.webp; )
| cat
| rg -v ^local.properties
| xargs -I {} darcs add {}
mherzl
  • 5,624
  • 6
  • 34
  • 75