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

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


当前回答

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

.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导入项目并生成其余部分。

其他回答

最好在整个开发过程中添加.gitignore列表,以防止版本控制由于某处预定义的(复制/粘贴)列表而无法工作时产生未知的副作用。对于我的一个项目,忽略列表只有:

.gradle
.idea
libs
obj
build
*.log

编译:

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

从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

我支持提交。idea文件夹(不包括workspace.xml和tasks.xml)。但我开始得出结论,.iml文件应该被忽略。

问题在于:

例如,在名为“foo”的目录下打开一个项目,你将得到foo。我和那一切看起来都很好。问题是,如果我只是将目录重命名为foo2(或克隆为另一个目录名),当你尝试在Android Studio中打开项目时,你会得到三件事:

一个名为foo2.iml的新iml文件 你的Android项目的iml文件将被更改为指向foo2作为它的父文件 .idea/modules.xml将为foo2添加一行。它既有旧的Iml文件,也有新目录的Iml文件

我找不到方法来阻止Android工作室做这个iml文件生成时,项目存储在一个不同的目录。将它们添加到源代码控制中会导致问题。因此,我认为也许我们应该忽略*。Iml文件和。idea/modules.xml