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

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

    There is NO NEED to add to the source control any of the following:

    .idea/
    .gradle/
    *.iml
    build/
    local.properties
    

    So you can configure hgignore or gitignore accordingly.

    The first time a developer clones the source control can go:

    1. Open Android Studio
    2. Import Project
    3. Browse for the build.gradle within the cloned repository and open it

    That's all

    PS: Android Studio will then, through maven, get the gradle plugin assuming that your build.gradle looks similar to this:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.12.2'
        }
    }
    
    allprojects {
        repositories {
            mavenCentral()
        }
    }
    

    Android studio will generate the content of .idea folder (including the workspace.xml, which shouldn't be in source control because it is generated) and the .gradle folder.

    This approach is Eclipse-friendly in the way that the source control does not really know anything about Android Studio. Android Studio just needs the build.gradle to import a project and generate the rest.

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

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

    Android Studio 4.1.1

    If you create a Gradle project using Android Studio the .gitignore file will contain the following:

    .gitignore

    *.iml
    .gradle
    /local.properties
    /.idea/caches
    /.idea/libraries
    /.idea/modules.xml
    /.idea/workspace.xml
    /.idea/navEditor.xml
    /.idea/assetWizardSettings.xml
    .DS_Store
    /build
    /captures
    .externalNativeBuild
    .cxx
    local.properties
    

    I would recommend ignoring the complete ".idea" directory because it contains user-specific configurations, nothing important for the build process.

    Gradle project folder

    The only thing that should be in your (Gradle) project folder after repository cloning is this structure (at least for the use cases I encountered so far):

    app/
    .git/
    gradle/
    build.gradle
    .gitignore
    gradle.properties
    gradlew
    gradlew.bat
    settings.gradle
    

    Note: It is recommended to check-in the gradle wrapper scripts (gradlew, gradlew.bat) as described here.

    To make the Wrapper files available to other developers and execution environments you’ll need to check them into version control.

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

    As of Android Studio 0.8.4 .gitignore file is generated automatically when starting new project. By default it contains:

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

    I agree with this statement, however I modify this file to change /build to build/ (This will include /build and /app/build) So I don't end up with all the files in app/build in my repository.

    Note also that if you import a project from Eclipse, the .gitignore won't be copied, or "automagically" created for you.

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

    .gitignore from AndroidRate library

    # Copyright 2017 - 2018 Vorlonsoft LLC
    #
    # Licensed under The MIT License (MIT)
    
    # Built application files
    *.ap_
    *.apk
    
    # Built library files
    *.aar
    *.jar
    
    # Built native files
    *.o
    *.so
    
    # Files for the Dalvik/Android Runtime (ART)
    *.dex
    *.odex
    
    # Java class files
    *.class
    
    # Generated files
    bin/
    gen/
    out/
    
    # Gradle files
    .gradle/
    build/
    
    # Local configuration file (sdk/ndk path, etc)
    local.properties
    
    # Windows thumbnail cache
    Thumbs.db
    
    # macOS
    .DS_Store/
    
    # Log Files
    *.log
    
    # Android Studio
    .navigation/
    captures/
    output.json
    
    # NDK
    .externalNativeBuild/
    obj/
    
    # IntelliJ
    ## User-specific stuff
    .idea/**/tasks.xml
    .idea/**/workspace.xml
    .idea/dictionaries
    ## Sensitive or high-churn files
    .idea/**/dataSources/
    .idea/**/dataSources.ids
    .idea/**/dataSources.local.xml
    .idea/**/dynamic.xml
    .idea/**/sqlDataSources.xml
    .idea/**/uiDesigner.xml
    ## Gradle
    .idea/**/gradle.xml
    .idea/**/libraries
    ## VCS
    .idea/vcs.xml
    ## Module files
    *.iml
    ## File-based project format
    *.iws
    
    0 讨论(0)
  • 2020-11-22 04:56

    This is created using the reference of http://gitignore.io/ Where you can create the latest updated gitignore file for any project. For Android http://gitignore.io/api/androidstudio. Hope this helps. Currently I am using Android Studio 3.6.3

    # Created by https://www.gitignore.io/api/androidstudio
    # Edit at https://www.gitignore.io/?templates=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)
提交回复
热议问题