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:53

I merge Github .gitignore files

### 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

查看更多
呛了眼睛熬了心
3楼-- · 2018-12-31 08:53

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.

查看更多
梦该遗忘
4楼-- · 2018-12-31 08:53

For Android Studio 3.0 projects use the following:

.gitignore

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

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
/gradle
.gitignore
build.gradle
build.properties
gradlew
gradle.bat
settings.gradle
查看更多
刘海飞了
5楼-- · 2018-12-31 08:53

Basically any file that is automatically regenerated.

A good test is to clone your repo and see if Android Studio is able to interpret and run your project immediately (generating what is missing).
If not, find what is missing, and make sure it isn't ignored, but added to the repo.

That being said, you can take example on existing .gitignore files, like the Android one.

# 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

# Eclipse project files
.classpath
.project

# Proguard folder generated by Eclipse
proguard/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/
查看更多
梦醉为红颜
6楼-- · 2018-12-31 08:54

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

查看更多
闭嘴吧你
7楼-- · 2018-12-31 08:55

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

查看更多
登录 后发表回答