What should be in my .gitignore for an Android Studio project?

What files should be in my .gitignore for an Android Studio project?

I have seen several examples that all include .iml but IntelliJ docs say that .iml must be included in your source control.


Updated to Android Studio 3.0 Please share missing items in comments.

A late answer but none of the answers here and here was right on the money for us...

So, here's our gitignore file:

#built application files
*.apk
*.ap_

# 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.

Edit Notes:

  • 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


  • 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 7/2015:

    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 .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings
  • All the .iml module 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.ids , datasources.xml can 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/libraries in case they are generated from Gradle project
  • Legacy project format ( .ipr / .iml / .iws files)

  • Share the project .ipr file and all the .iml module files, don't share the .iws file 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
    
    链接地址: http://www.djcxy.com/p/44830.html

    上一篇: 执行git合并时可以排除特定的提交吗?

    下一篇: Android Studio项目的.gitignore中应该包含什么内容?