什么文件应该在我的。gitignore为一个Android工作室项目?

我见过几个包含。iml的例子,但是IntelliJ文档说。iml必须包含在你的源代码控制中。


当前回答

这份来自JetBrains Support的官方文档认为应该包含以下内容:

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

它还给出了其他需要注意的事项的建议。

其他回答

更新到Android Studio 3.0 请在评论中分享遗漏的项目。

一个迟来的答案,但这个替代答案不适合我们……

这是我们的gitignore文件:

#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

从Android Studio 2.2到3.0,新项目都是用这个gitignore文件创建的:

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

已弃用-对于旧的项目格式,将此部分添加到您的gitignore文件:


/*/out
/*/*/build
/*/*/production
*.iws
*.ipr
*~
*.swp

该文件应该位于项目的根文件夹中,而不是在项目的模块文件夹中。

编辑笔记:

从0.3+版本开始,似乎你可以提交和推送*。我和建造。gradle文件。如果你的项目基于Gradle:在新的打开/导入对话框中,你应该选中“使用自动导入”复选框,并标记“使用默认Gradle包装器(推荐)”单选按钮。所有路径现在都是相对的@George建议。 根据@128KB附件来源和@Skela建议更新了答案

Github为各种项目维护有用的gitignore条目。 下面是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/libraries

# Keystore files
*.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

安卓Gitignore在github

我不同意所有这些答案。下面的配置非常适合我们组织的应用程序。

我忽略:

/构建 /。想法(可能有例外,见dalewking回答中的评论) * .iml local.properties

我想几乎每个人都同意/建造。

我厌倦了经常看到关于Gradle在/.idea中创建或删除的各种library.xml文件的消息。构建。当开发人员第一次签出项目时,gradle将在他们的本地运行,那么为什么这些XML文件需要版本控制呢?Android Studio也会生成/的剩余部分。当开发人员使用版本控制签出创建项目时,为什么该文件夹中的任何东西都需要进行版本控制?

如果*。Iml的版本是一个新用户将必须命名项目完全相同,当它被提交。既然这也是一个生成的文件,那么为什么首先要为它设置版本呢?

当地的。properties文件指向SDK文件系统上的绝对路径,因此绝对不应该对其进行版本控制。

编辑1:添加.gradle来忽略gradle缓存不应该被版本化的东西(感谢Vasily Makarov)。

编辑2:添加. ds_store现在我使用Mac。这个文件夹是Mac特定的,不应该被版本化。

另外注意:在构建发布版本时,您可能还想添加一个目录来放置签名密钥。

为方便复制/粘贴:

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

为了避免所有文件的导入,Android Studio忽略“Ignored files”列表,但仍然利用Android Studio VCS,我做了以下工作: 这将使用Android Studio中的“忽略文件”列表(导入后!并且避免使用龟SVN设置SVN:ignore列表的繁琐方式。

使用Tortoise SVN存储库浏览器直接在存储库中创建一个新的项目文件夹。 使用Tortoise SVN在要导入的文件夹上方签出新文件夹。您将得到一个警告,说明本地文件夹不是空的。忽略警告。现在,您有了一个版本化的顶级文件夹,其中包含未版本化的内容。 从本地工作目录打开项目。VCS现在应该自动启用了 在“文件->设置->版本控制->忽略文件”中设置文件例外 从Android Studio添加文件到SVN:在项目结构中选择“App”-> VCS ->添加到VCS(这将添加所有文件,除了“忽略文件”) 提交修改

下一步,“被忽略的文件”将被忽略,你仍然可以从Android Studio管理VCS。

干杯, -Joost

我有忽略构建文件的问题,但这似乎是有效的:-)

# 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

# Android Studio
.idea/
.gradle
/*/local.properties
/*/out
/*/*/build
/*/*/production
*.iml
*.iws
*.ipr
*~
*.swp

*/build
*/production
*/local.properties
*/out