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

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


当前回答

更新到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建议更新了答案

其他回答

我是kosher添加。iml文件和Intellij sez添加。idea文件夹,但忽略。idea/workspace.xml和。idea/tasks.xml,但。idea/libraries/呢?

我不明白加这个有什么意义。它有一个XML文件列表,列出了Android Studio项目应该知道的库。这些应该来自于构建。gradle定义的依赖项——不是IDE项目文件。

其中一个文件的内容是这样的:

<component name="libraryTable">
    <CLASSES>
       <root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.example/example/etc...jar!"/>

这样做没有意义。如果用户为gradle指定了不同的主目录,或者如果他们使用了不同的gradle版本,.gradle/caches/artifacts-xxx下的路径对他们来说将是不同的(即工件-在末尾追加的数字将与您正在使用的gradle版本发布相关)。这些路径不是通用的,但建议是检查所有这些?

在我正常的Android .gitignore的基础上,在阅读Intellij IDEA网站上的文档和阅读StackOverflow上的帖子后,我构建了以下文件:

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# built native files (uncomment if you build your own)
# *.o
# *.so

# generated files
bin/
gen/

# Ignore gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Eclipse Metadata
.metadata/

# Mac OS X clutter
*.DS_Store

# Windows clutter
Thumbs.db

# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
.idea/workspace.xml
.idea/tasks.xml
.idea/datasources.xml
.idea/dataSources.ids

还要注意,正如所指出的,当你用Android NDK构建自己的本机代码时,构建的本机文件部分主要是有用的。另一方面,如果您正在使用包含这些文件的第三方库,则可能希望删除这些行(*。O和*.so)来自你的。gitignore。

从Android Studio 0.8.4开始,启动新项目时自动生成gitignore文件。 默认情况下,它包含:

.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build

基本上是自动重新生成的任何文件。

一个很好的测试是克隆你的repo,看看Android Studio是否能够立即解释和运行你的项目(生成缺少的东西)。 如果没有,找到丢失的内容,并确保它没有被忽略,而是添加到回购中。

也就是说,你可以在现有的.gitignore文件上举例,比如Android文件。

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

编译:

#built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Gradle files
.gradle/
build/
/*/build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Windows thumbnail db
Thumbs.db

# OSX files
.DS_Store

# Eclipse project files
.classpath
.project

# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/

# Intellij project files
*.iml
*.ipr
*.iws
.idea/