Androidstudio项目中的Git应该忽略哪些文件夹[重复]

Posted

技术标签:

【中文标题】Androidstudio项目中的Git应该忽略哪些文件夹[重复]【英文标题】:What folders should be ignored by Git in an Androidstudio Project [duplicate] 【发布时间】:2018-10-01 01:44:56 【问题描述】:

我问我,在 androidStudio 项目中 Git 应该明确忽略哪些文件夹?

例如。是否应该忽略“.idea”?

【问题讨论】:

发帖前请检查SO:***.com/questions/3041154/… 一般情况下,您只想对项目中的任何人都通用的源代码进行版本控制。如果您是唯一的贡献者,并且您确定情况总是如此,那么您可以打开一点并添加一些本地配置文件。 【参考方案1】:

通常,您需要将.idea 目录添加到您的.gitignore 中,因为它与您的Android Studio 外部插件相关,只是您的项目始终依赖外部插件。

这是你的 .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

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

# Windows thumbnail db
Thumbs.db

# Windows desktop.ini
desktop.ini

# Linux configuration file
.directory

# OSX files
.DS_Store

# Don't include your google key, depends on your module name.
/app/google-services.json
/app/src/release/res/values/google_maps_api.xml

【讨论】:

非常感谢您提供的优质服务。【参考方案2】:

我使用gitignore.io 来生成我的基本 .gitignore 文件。

Here's the one for AndroidStudio

# Created by https://www.gitignore.io/api/androidstudio

### AndroidStudio ###
# Covers files to be ignored for android development using Android Studio.

# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle
.gradle/
build/

# Signing files
.signing/

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

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
/*/*/production
captures/
.navigation/
*.ipr
*~
*.swp

# Android Patch
gen-external-apklibs

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

# NDK
obj/

# IntelliJ IDEA
*.iml
*.iws
/out/

# User-specific configurations
.idea/caches/
.idea/libraries/
.idea/shelf/
.idea/workspace.xml
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
.idea/datasources.xml
.idea/dataSources.ids
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# OS-specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Legacy Eclipse project files
.classpath
.project
.cproject
.settings/

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.war
*.ear

# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
hs_err_pid*

## Plugin-specific files:

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Mongo Explorer plugin
.idea/mongoSettings.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### AndroidStudio Patch ###

!/gradle/wrapper/gradle-wrapper.jar


# End of https://www.gitignore.io/api/androidstudio

【讨论】:

【参考方案3】:

在创建项目时选择本地 git 仓库作为目标文件夹,Android Studio 会自动生成一个 .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

【讨论】:

以上是关于Androidstudio项目中的Git应该忽略哪些文件夹[重复]的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio SVN/Git之忽略文件

我应该忽略 git 中的 UnserInterfaceState 和 xcschememanagement 文件吗? [复制]

Android Studio 使用git协同开发之忽略文件

Git 不会忽略 .gitignore 中的某些 Xcode 文件

git 无法忽略Android Studio 生成的 .idea目录解决办法

Android Studio从Git上Clone(克隆)项目