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

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


当前回答

编译:

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

其他回答

这份来自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

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

不需要在源代码控件中添加以下任何内容:

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

所以你可以相应地配置hgignore或gitignore。

开发人员第一次克隆源代码控件时可以这样做:

Open Android Studio 导入项目 浏览构建。Gradle在克隆的存储库中并打开它

这是所有

PS: Android Studio将通过maven获得gradle插件,假设您的构建。Gradle看起来像这样:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

Android studio将生成.idea文件夹(包括workspace.xml,它不应该在源代码控制中,因为它是生成的)和.gradle文件夹的内容。

这种方法是eclipse友好的,因为源代码控制并不真正了解Android Studio。Android Studio只需要构建。Gradle导入项目并生成其余部分。

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 JetBrains.gitignore

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

请阅读:JetBrains支持:如何在版本控制系统下管理项目

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