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

后端 未结 30 3383
星月不相逢
星月不相逢 2020-11-22 04:23

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

I\'ve seen several examples that all include .iml but IntelliJ docs sa

相关标签:
30条回答
  • 2020-11-22 04:49

    Depends on how your project format is maintained:

    You have two options:

    1. Directory-based format (You will have a .idea folder which contains the project specific files)
    2. File-based format (configuration files are .iws and .ipr)

    Ref: http://www.jetbrains.com/idea/webhelp/project.html

    Files committed to version control depends on the above:

    1. Include .idea folder to version control, exclude workspace.xml and tasks.xml
    2. Version control .ipr file and all the .iml module files, exclude the .iws file as it stores user specific settings.

    Ref: https://intellij-support.jetbrains.com/entries/23393067

    0 讨论(0)
  • 2020-11-22 04:50

    I disagree with all of these answers. The following configuration is working great for our organization's app.

    I ignore:

    • /build
    • /.idea (with possible exceptions, see comments in dalewking's answer)
    • *.iml
    • local.properties

    I think almost everyone agrees about /build.

    I got sick of constantly seeing messages about the various library.xml files that Gradle creates or deletes in /.idea. The 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?

    If the *.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?

    The 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 
    
    0 讨论(0)
  • 2020-11-22 04:50

    I merge Github .gitignore files

    • Android.gitignore
    • JetBrains.gitignore
    ### Github Android.gitignore ### 
    
    # Built application files
    *.apk
    *.ap_
    
    # Files for the Dalvik VM
    *.dex
    
    # Java class files
    *.class
    
    # Generated files
    bin/
    gen/
    
    # 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/
    
    ### Github JetBrains.gitignore ### 
    
    # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
    
    *.iml
    
    ## Directory-based project format:
    .idea/
    # if you remove the above rule, at least ignore the following:
    
    # User-specific stuff:
    # .idea/workspace.xml
    # .idea/tasks.xml
    # .idea/dictionaries
    
    # Sensitive or high-churn files:
    # .idea/dataSources.ids
    # .idea/dataSources.xml
    # .idea/sqlDataSources.xml
    # .idea/dynamic.xml
    # .idea/uiDesigner.xml
    
    # Gradle:
    # .idea/gradle.xml
    # .idea/libraries
    
    # Mongo Explorer plugin:
    # .idea/mongoSettings.xml
    
    ## File-based project format:
    *.ipr
    *.iws
    
    ## Plugin-specific files:
    
    # IntelliJ
    /out/
    
    # mpeltonen/sbt-idea plugin
    .idea_modules/
    
    # JIRA plugin
    atlassian-ide-plugin.xml
    
    # Crashlytics plugin (for Android Studio and IntelliJ)
    com_crashlytics_export_strings.xml
    crashlytics.properties
    crashlytics-build.properties
    

    Please read: JetBrains Support: How to manage projects under Version Control Systems

    0 讨论(0)
  • 2020-11-22 04:51

    Github maintains useful gitignore items for various kinds of projects. Here is the list of useful gitignore items for android projects.

    # Built application files
    *.apk
    *.ap_
    
    # Files for the ART/Dalvik VM
    *.dex
    
    # Java class files
    *.class
    
    # Generated files
    bin/
    gen/
    out/
    
    # 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/libraries
    
    # Keystore files
    *.jks
    
    # External native build folder generated in Android Studio 2.2 and later
    .externalNativeBuild
    
    # Google Services (e.g. APIs or Firebase)
    google-services.json
    
    # Freeline
    freeline.py
    freeline/
    freeline_project_description.json
    

    Android Gitignore in github

    0 讨论(0)
  • 2020-11-22 04:52

    My advise would be also to not ignore the .idea folder.

    I've imported a Git-based Eclipse project to Android Studio and that went fine. Later, I wanted to import this project with Git (like the first time) to another machine with Android Studio, but that didn't worked. Android Studio did load all the files but wasn't able to "see" the project as a project. I only could open Git-files.

    While importing the project for the first time (from Eclipse to Android Studio) my old .gitignore was overwritten and the new one looked like this:

    • .idea/.name
    • .idea/compiler.xml
    • .idea/copyright/profiles_settings.xml
    • .idea/encodings.xml
    • .idea/libraries/libs.xml
    • .idea/misc.xml
    • .idea/modules.xml
    • .idea/scopes/scope_settings.xml
    • .idea/vcs.xml
    • .idea/workspace.xml

    So, I tried to use an empty gitignore and now it worked. The other Android Studio could load the files and the Project. I guess some files are not important (profiles_settings.xml) for Git and importing but I am just happy it worked.

    0 讨论(0)
  • 2020-11-22 04:54

    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.

    0 讨论(0)
提交回复
热议问题