git - Android Studio 项目的 .gitignore 中应该包含什么?

标签 git android-studio gitignore

对于 Android Studio 项目,我的 .gitignore 中应该包含哪些文件?

我见过几个例子都包含 .iml 但 IntelliJ 文档说 .iml 必须包含在您的源代码管理中。

最佳答案

已更新至 Android Studio 3.0 请在评论中分享缺少的项目。

一个迟到的答案,但 this替代答案不适合我们...

所以,这是我们的 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

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

编辑备注:

  1. 从 0.3+ 版开始,您似乎可以提交和推送 *.imlbuild.gradle 文件。如果您的项目基于 Gradle:在新的打开/导入对话框中,您应该选中 "use auto import" 复选框并标记 "use default gradle wrapper (recommended)"单选按钮。正如@George 建议的那样,所有路径现在都是相对的。

  2. 根据@128KB attached source 更新答案和@Skela 建议

关于git - Android Studio 项目的 .gitignore 中应该包含什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16640566/

相关文章:

android - Android Studio 构建错误

android - 输入字符串错误 : "12" Android studio

git - 告诉 git 永远不要更新文件

git - 如何在 git 的历史记录中找到所有包含提交的引用

python - 获取传递给 git merge 的分支名称

git - SourceTree merge 忽略空格冲突

android - android构建系统中不再有Android.mk吗?

php - Git 忽略 .git 文件夹

gitignore - .gitignore 似乎没有生效

git - .gitignore 不会忽略该目录