什么文件应该在我的。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建议更新了答案

其他回答

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

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

Android Studio 3.5.3

我在我的库和项目中使用这个,它涵盖了大多数由android studio和其他著名工具生成的文件:

# Built application files
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Generated files
bin/
gen/
out/
app/release/

# Gradle files
.gradle/
build/

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

# 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/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

#NDK
*.so

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

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

一个很好的测试是克隆你的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/