The best answers to the question “What should be in my .gitignore for an Android Studio project?” in the category Dev.
What files should be in my
.gitignore for an Android Studio project?
I’ve seen several examples that all include
.iml but IntelliJ docs say that
.iml must be included in your source control.
Building on my normal Android .gitignore, and after reading through documentation on the Intellij IDEA website and reading posts on StackOverflow, I have constructed the following file:
# built application files *.apk *.ap_ # files for the dex VM *.dex # Java class files *.class # built native files (uncomment if you build your own) # *.o # *.so # generated files bin/ gen/ # Ignore gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Eclipse Metadata .metadata/ # Mac OS X clutter *.DS_Store # Windows clutter Thumbs.db # Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067) .idea/workspace.xml .idea/tasks.xml .idea/datasources.xml .idea/dataSources.ids
Also note that as pointed out, the built native files section is primarily useful when you are building your own native code with the Android NDK. If, on the other hand, you are using a third party library that includes these files, you may wish to remove these lines (*.o and *.so) from your .gitignore.
Updated to Android Studio 3.0
Please share missing items in comments.
A late answer but this alternative answer was not right for us …
So, here’s our gitignore file:
#built application files *.apk *.ap_ *.aab # files for the dex VM *.dex # Java class files *.class # generated files bin/ gen/ # Local configuration file (sdk path, etc) local.properties # Windows thumbnail db Thumbs.db # OSX files .DS_Store # Android Studio *.iml .idea #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. .gradle build/ .navigation captures/ output.json #NDK obj/ .externalNativeBuild
Since Android Studio 2.2 and up to 3.0, new projects are created with this gitignore file:
*.iml .gradle /local.properties /.idea/workspace.xml /.idea/libraries .DS_Store /build /captures .externalNativeBuild
Deprecated – for older project format, add this section to your gitignore file:
/*/out /*/*/build /*/*/production *.iws *.ipr *~ *.swp
This file should be located in the project’s root folder and not inside the project’s module folder.
Since version 0.3+ it seems you can commit and push *.iml and build.gradle files. If your project is based on Gradle: in the new open/import dialog, you should check the
"use auto import"checkbox and mark the
"use default gradle wrapper (recommended)"radio button. All paths are now relative as @George suggested.
Updated answer according to @128KB attached source and @Skela suggestions
I disagree with all of these answers. The following configuration is working great for our organization’s app.
/.idea(with possible exceptions, see comments in dalewking’s answer)
I think almost everyone agrees about
I got sick of constantly seeing messages about the various
library.xml files that Gradle creates or deletes in
build.gradle will run on the developers’s local when they first check out the project, so why do those XML files need to be versioned? Android Studio will also generate the rest of
/.idea when a developer creates a project using
Check out from Version Control, so why does anything in that folder need to be versioned?
*.iml is versioned a new user will have to name the project exactly the same as it was when committed. Since this is also a generated file, why version it in the first place?
local.properties files points to an absolute path on the file system for the SDK, so it definitely shouldn’t be versioned.
Edit 1: Added
.gradle to ignore the gradle caching stuff that should not be versioned (thanks Vasily Makarov).
Edit 2: Added
.DS_Store now that I am using Mac. This folder is Mac specific and should not be versioned.
Additional note: You probably also want to add a directory to put your signing keys in when building a release version.
For copy/paste convenience:
.gradle /build /.idea *.iml local.properties .DS_Store
Here is the definitive source from JetBrains
Directory based project format (.idea directory)
This format is used by all the recent IDE versions by default. Here is what you need to share:
- All the files under
.ideadirectory in the project root except the
tasks.xmlfiles which store user specific settings
- All the
.imlmodule files that can be located in different module directories (applies to IntelliJ IDEA)
Be careful about sharing the following:
- Android artifacts that produce a signed build (will contain keystore passwords)
- In IDEA 13 and earlier
datasources.xmlcan contain database passwords. IDEA 14 solves this problem.
You may consider not to share the following:
- gradle.xml file, see this discussion
- user dictionaries folder (to avoid conflicts if other developer has the same name)
- XML files under
.idea/librariesin case they are generated from Gradle project
Legacy project format (
- Share the project
.iprfile and all the
.imlmodule files, don’t share the
.iwsfile as it stores user specific settings
While these instructions are for IntelliJ IDEA, they hold true 100% for Android Studio.
Here is a
.gitignore snippet that incorporates all of the above rules:
# Android Studio / IntelliJ IDEA *.iws .idea/libraries .idea/tasks.xml .idea/vcs.xml .idea/workspace.xml