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

后端 未结 30 3345
星月不相逢
星月不相逢 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:42

    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_
    *.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.

    Edit Notes:

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

    2. Updated answer according to @128KB attached source and @Skela suggestions

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

    In the case of Android Studio, the only files that are required to be saved in version control are the files required to build the application from the command line using gradle. So you can ignore:

    • *.iml
    • .idea
    • build

    However, if you save any IDE settings, such as custom code style settings, they get saved in the .idea folder. If you want those changes in version control, then you'd save the IDEA files as well (*.iml and .idea).

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

    Using the api provided by gitignore.io, you can get is automatically generated. Here is the direct-link also gitignore.io/api/androidstudio

    ### AndroidStudio ###
    # Covers files to be ignored for android development using Android Studio.
    
    # Built application files
    *.apk
    *.ap_
    
    # Files for the ART/Dalvik VM
    *.dex
    
    # Java class files
    *.class
    
    # Generated files
    bin/
    gen/
    out/
    
    # Gradle files
    .gradle
    .gradle/
    build/
    
    # Signing files
    .signing/
    
    # Local configuration file (sdk path, etc)
    local.properties
    
    # Proguard folder generated by Eclipse
    proguard/
    
    # Log Files
    *.log
    
    # Android Studio
    /*/build/
    /*/local.properties
    /*/out
    /*/*/build
    /*/*/production
    captures/
    .navigation/
    *.ipr
    *~
    *.swp
    
    # Android Patch
    gen-external-apklibs
    
    # External native build folder generated in Android Studio 2.2 and later
    .externalNativeBuild
    
    # NDK
    obj/
    
    # IntelliJ IDEA
    *.iml
    *.iws
    /out/
    
    # User-specific configurations
    .idea/caches/
    .idea/libraries/
    .idea/shelf/
    .idea/workspace.xml
    .idea/tasks.xml
    .idea/.name
    .idea/compiler.xml
    .idea/copyright/profiles_settings.xml
    .idea/encodings.xml
    .idea/misc.xml
    .idea/modules.xml
    .idea/scopes/scope_settings.xml
    .idea/dictionaries
    .idea/vcs.xml
    .idea/jsLibraryMappings.xml
    .idea/datasources.xml
    .idea/dataSources.ids
    .idea/sqlDataSources.xml
    .idea/dynamic.xml
    .idea/uiDesigner.xml
    .idea/assetWizardSettings.xml
    
    # OS-specific files
    .DS_Store
    .DS_Store?
    ._*
    .Spotlight-V100
    .Trashes
    ehthumbs.db
    Thumbs.db
    
    # Legacy Eclipse project files
    .classpath
    .project
    .cproject
    .settings/
    
    # Mobile Tools for Java (J2ME)
    .mtj.tmp/
    
    # Package Files #
    *.war
    *.ear
    
    # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
    hs_err_pid*
    
    ## Plugin-specific files:
    
    # mpeltonen/sbt-idea plugin
    .idea_modules/
    
    # JIRA plugin
    atlassian-ide-plugin.xml
    
    # Mongo Explorer plugin
    .idea/mongoSettings.xml
    
    # Crashlytics plugin (for Android Studio and IntelliJ)
    com_crashlytics_export_strings.xml
    crashlytics.properties
    crashlytics-build.properties
    fabric.properties
    
    ### AndroidStudio Patch ###
    
    !/gradle/wrapper/gradle-wrapper.jar
    
    # End of https://www.gitignore.io/api/androidstudio
    
    0 讨论(0)
  • 2020-11-22 04:42

    This official documentation from JetBrains Support says the following should be included:

    All files under .idea directory except workspace.xml and tasks.xml because
        they store specific user settings
    All the *.iml files that can be located in different module directories
    

    It also gives other recommendations of things to be careful about.

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

    Android Studio 3.5.3

    I use this for my libraries and projects and it covers most of the files that generate by android studio and other famous tools:

    # Built application files
    *.apk
    *.ap_
    *.aab
    
    # Files for the ART/Dalvik VM
    *.dex
    
    # Generated files
    bin/
    gen/
    out/
    app/release/
    
    # Gradle files
    .gradle/
    build/
    
    # Local configuration file (sdk path, etc)
    local.properties
    
    # 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
    .idea/caches
    
    # 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
    
    # Freeline
    freeline.py
    freeline/
    freeline_project_description.json
    
    # fastlane
    fastlane/report.xml
    fastlane/Preview.html
    fastlane/screenshots
    fastlane/test_output
    fastlane/readme.md
    
    #NDK
    *.so
    
    0 讨论(0)
  • 2020-11-22 04:46

    I'm kosher with adding the .iml files and Intellij sez to add the .idea folder but ignore .idea/workspace.xml and .idea/tasks.xml, but what about .idea/libraries/ ?

    I don't see how it makes sense to add this. It has a list of XML files that list libraries the Android Studio project is supposed to know about. These are supposed to come instead from build.gradle defined dependencies -- not an IDE project file.

    Also the contents of one of these files looks like this:

    <component name="libraryTable">
        <CLASSES>
           <root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.example/example/etc...jar!"/>
    

    It doesn't make sense to commit this. What if the user specified a different home dir for gradle, or if they use a different gradle version, the path under .gradle/caches/artifacts-xxx is going to be different for them (i.e. artifacts- the number appended on the end will relate to the gradle version release you are using.) These paths are not universal, and yet the advice is to check all this in?

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