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

后端 未结 30 3381
星月不相逢
星月不相逢 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 05:07

    It's the best way to generate .gitignore via here

    0 讨论(0)
  • 2020-11-22 05:07

    Tested with Android Studio 3.0

    You might need to Install .ignore plugin.

    You can auto-generate the .gitignore file for Android. Right click on folder and follow

    Then Select Android from left panel and click Generate

    Android Studio will generate .gitignore file which contains all the file need to ignore.

    Taken from http://menukanows.com/how-to-add-gitignore-file-in-android-project/

    0 讨论(0)
  • 2020-11-22 05:07

    https://github.com/github/gitignore is awesome collection

    Android.gitignore

    # 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/assetWizardSettings.xml
    .idea/dictionaries
    .idea/libraries
    .idea/caches
    
    # Keystore files
    # Uncomment the following line if you do not want to check your keystore files in.
    #*.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
    
    # fastlane
    fastlane/report.xml
    fastlane/Preview.html
    fastlane/screenshots
    fastlane/test_output
    fastlane/readme.md
    
    0 讨论(0)
  • 2020-11-22 05:08

    I know this is an old topic and there are certainly a lot of options, but I really prefer gibo by Simon Whitaker. It's super simple to use, cross-platform (mac, *nix, and windows), and uses the github gitignore repo so it is (basically) always up to date.

    Make sure your local cache is up to date:

        $ gibo --upgrade
        From https://github.com/github/gitignore
         * branch            master     -> FETCH_HEAD
        Current branch master is up to date.
    

    Search for the language/technology you need:

        $ gibo --search android
        Android
    

    Display the .gitignore file:

        $ gibo Android
        ### Android
    
        # 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
    

    Now, append it to your project's .gitignore file:

        $ gibo Android >> .gitignore
    

    (Make sure you use >> to append to your project's .gitignore file; one > will overwrite it - as I've done many times on accident!)

    I know this isn't answering the OP's exact question, but using gibo makes it so you pretty much don't have to think about 'the question' anymore! .. it's nice! ;)

    0 讨论(0)
  • 2020-11-22 05:08

    To get a better idea, all you need are the following files

    • app
    • build.gradle
    • settings.gradle

    You could put everything else in the .gitignore file. All your app changes lies mostly in these files and folders. The rest you see in a basic project are gradle build files or Android Studio configuration files.

    If you are using Android Studio, you can use "Import project" to successfully build the project. Alternatively you can build using command line, follow Building Android Projects with Gradle.

    0 讨论(0)
  • 2020-11-22 05:09

    I support the committing of .idea folder (excluding workspace.xml and tasks.xml). But I am starting to come to the conclusion that .iml files should be ignored.

    Here is the issue:

    Open a project in a directory named "foo" for example and you will get foo.iml and that all seems well and good. The problem is that if I simply rename the directory to foo2 (or clone it into another directory name) when you try to open the project in Android Studio you will get three things:

    • A new iml file named foo2.iml
    • The iml file for your Android project will be changed to point now to foo2 as its parent
    • .idea/modules.xml will have a line added for foo2.iml so it has both the old iml file and the one for the new directory

    I can find no way to prevent Android Studio from doing this iml file generation when the project is stored in a different directory. Adding them to source control is going to cause problems. Therefore I think perhaps we should ignore *.iml files and .idea/modules.xml

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