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

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


当前回答

我有忽略构建文件的问题,但这似乎是有效的:-)

# 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

# Android Studio
.idea/
.gradle
/*/local.properties
/*/out
/*/*/build
/*/*/production
*.iml
*.iws
*.ipr
*~
*.swp

*/build
*/production
*/local.properties
*/out

其他回答

https://github.com/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/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches

# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.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

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

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

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

为了更好地理解,您只需要以下文件

应用程序 build.gradle settings.gradle

您可以将其他所有内容放在.gitignore文件中。你所有的应用变化都在这些文件和文件夹中。你在基本项目中看到的其他文件是gradle构建文件或Android Studio配置文件。

如果你正在使用Android Studio,你可以使用“Import project”来成功构建项目。或者你也可以使用命令行构建,使用Gradle构建Android项目。

Android Studio Chipmunk 2021.2.1

如果你使用Android Studio创建Gradle项目,.gitignore文件将包含以下内容:

. gitignore

*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

我建议忽略完整的”。目录,因为它包含特定于用户的配置,对于构建过程没有什么重要的。

Gradle项目文件夹

在存储库克隆之后,你的(Gradle)项目文件夹中唯一应该存在的东西是这样的结构(至少对于我目前遇到的用例来说是这样的):

app/
.git/
gradle/
build.gradle
.gitignore
gradle.properties
gradlew
gradlew.bat
settings.gradle

注意:建议像这里描述的那样签入gradle包装器脚本(gradlew, gradlew.bat)。

要使Wrapper文件对其他开发人员和执行环境可用,您需要将它们检入版本控制。

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

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