What should be in my .gitignore for an Android Stu

2018-12-31 08:06发布

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

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

30条回答
唯独是你
2楼-- · 2018-12-31 08:56

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! ;)

查看更多
无色无味的生活
3楼-- · 2018-12-31 08:56

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.

查看更多
何处买醉
4楼-- · 2018-12-31 08:56

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:

  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

查看更多
浪荡孟婆
5楼-- · 2018-12-31 08:57

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

  • app
  • build.gradle
  • settings.gradle

Basic Android project structure

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.

查看更多
人气声优
6楼-- · 2018-12-31 08:57

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

Add .gitignore file

Then Select Android from left panel and click Generate

Generate .gitignore file

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/

查看更多
牵手、夕阳
7楼-- · 2018-12-31 08:59

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
查看更多
登录 后发表回答