对于Android Studio项目,我的.gitignore应该是什么?
android studio gitignore (20)
对于Android Studio项目,我的.gitignore
应包含哪些文件?
我已经看到几个例子都包含.iml
但IntelliJ文档说.iml
必须包含在你的源代码管理中。
.gitignore from AndroidRate library
# Copyright 2017 - 2018 Vorlonsoft LLC
#
# Licensed under The MIT License (MIT)
# Built application files
*.ap_
*.apk
# Built library files
*.aar
*.jar
# Built native files
*.o
*.so
# Files for the Dalvik/Android Runtime (ART)
*.dex
*.odex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk/ndk path, etc)
local.properties
# Windows thumbnail cache
Thumbs.db
# macOS
.DS_Store/
# Log Files
*.log
# Android Studio
.navigation/
captures/
output.json
# NDK
.externalNativeBuild/
obj/
# IntelliJ
## User-specific stuff
.idea/**/tasks.xml
.idea/**/workspace.xml
.idea/dictionaries
## Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/dynamic.xml
.idea/**/sqlDataSources.xml
.idea/**/uiDesigner.xml
## Gradle
.idea/**/gradle.xml
.idea/**/libraries
## VCS
.idea/vcs.xml
## Module files
*.iml
## File-based project format
*.iws
github.com/github/gitignore is awesome collection
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
2015年7月更新:
基于目录的项目格式(.idea目录)
默认情况下,所有最新的IDE版本都使用此格式。 以下是您需要分享的内容:
- 项目根目录下
.idea
目录下的所有文件, 除了存储用户特定设置的workspace.xml
和tasks.xml
文件 - 所有
.iml
模块文件都可以位于不同的模块目录中(适用于IntelliJ IDEA)
分享以下内容时要小心 :
- 产生签名版本的Android工件(将包含密钥库密码)
- 在IDEA 13及更早版本的
dataSources.ids
,datasources.xml
可以包含数据库密码。 IDEA 14 解决了这个问题 。
您可以考虑不要分享以下内容:
- gradle.xml文件,请参阅此讨论
- 用户词典文件夹(以避免在其他开发人员具有相同名称时发生冲突)
- 它们是从Gradle项目生成的
.idea/libraries
下的XML文件
旧项目格式( .ipr
/ .iml
/ .iws
文件)
- 共享项目
.ipr
文件和所有.iml
模块文件, 不要共享.iws
文件,因为它存储用户特定的设置
虽然这些说明适用于IntelliJ IDEA,但它们对于Android Studio来说却是100%真实的。
这是一个包含以上所有规则的.gitignore
片段:
# Android Studio / IntelliJ IDEA
*.iws
.idea/libraries
.idea/tasks.xml
.idea/vcs.xml
.idea/workspace.xml
使用Android Studio 3.0进行测试
您可能需要安装.ignore插件。
您可以为Android自动生成.gitignore文件。 右键单击文件夹并按照
然后从左侧面板中选择Android,然后单击Generate
Android Studio将生成.gitignore文件,其中包含需要忽略的所有文件。
摘自http://menukanows.com/how-to-add-gitignore-file-in-android-project/
Compilation:
#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/
Github maintains useful gitignore items for various kinds of projects. Here is the list of useful gitignore items for android projects.
# 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
To circumvent the import of all files, where Android Studio ignores the "Ignored Files" list, but still leverage Android Studio VCS, I did the following: This will use the "Ignored Files" list from Android Studio (after import! not during) AND avoid having to use the cumbersome way Tortoise SVN sets the svn:ignore list.
- Use the Tortoise SVN repository browser to create a new project folder directly in the repository.
- Use Tortoise SVN to checkout the new folder over the top of the folder you want to import. You will get a warning that the local folder is not empty. Ignore the warning. Now you have a versioned top level folder with unversioned content.
- Open your project from the local working directory. VCS should now be enabled automatically
- Set your file exceptions in File -> Settings -> Version Control -> Ignored Files
- Add files to SVN from Android Studio: select 'App' in Project Structure -> VCS -> Add to VCS (this will add all files, except "Ignored Files")
- Commit Changes
Going forward, "Ignored Files" will be ignored and you can still manage VCS from Android Studio.
Cheers, -Joost
为了获得更好的想法,您只需要以下文件即可
- 应用
- 的build.gradle
- settings.gradle
您可以将其他所有内容放在.gitignore文件中。 您的所有应用更改主要位于这些文件和文件夹中。 您在基本项目中看到的其余部分是gradle构建文件或Android Studio配置文件。
如果您使用的是Android Studio,则可以使用“导入项目”来成功构建项目。 或者,您可以使用命令行构建,请按照使用Gradle构建Android项目 。
从Android Studio开始,0.8.4 .gitignore
文件在启动新项目时自动生成。 默认情况下,它包含:
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
取决于您的项目格式的维护方式:
你有两个选择:
- 基于目录的格式(您将有一个包含项目特定文件的
.idea
文件夹) - 基于文件的格式(配置文件为
.iws
和.ipr
)
参考: http://www.jetbrains.com/idea/webhelp/project.html : http://www.jetbrains.com/idea/webhelp/project.html
提交版本控制的文件取决于以上内容:
- 将.idea文件夹包含到版本控制中,排除
workspace.xml
和tasks.xml
- 版本控制
.ipr
文件和所有.iml
模块文件,在存储用户特定设置时排除.iws
文件。
参考: https : //intellij-support.jetbrains.com/entries/23393067
基本上任何自动重新生成的文件。
一个好的测试是克隆你的repo,看看Android Studio是否能够立即解释和运行你的项目(生成缺少的东西)。
如果没有,找到缺少的东西,并确保它不被忽略,但添加到repo。
话虽这么说,你可以举例说明现有的.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/
对于Android Studio 3.0项目,请使用以下内容:
的.gitignore
.gradle
.idea
*.iml
gradle.properties
local.properties
.DS_Store
build
Gradle项目文件夹
在存储库克隆之后,您的(Gradle)项目文件夹中唯一应该是这种结构(至少对于我到目前为止遇到的用例):
/app
/gradle
.gitignore
build.gradle
build.properties
gradlew
gradle.bat
settings.gradle
我不同意所有这些答案。 以下配置适用于我们组织的应用程序。
我忽略了:
-
/build
-
/.idea
(可能有例外,请参阅dalewking答案中的评论) -
*.iml
-
local.properties
我想几乎每个人都同意/build
。
我厌倦了不断看到有关Gradle在/.idea
创建或删除的各种library.xml
文件的消息。 build.gradle
将在首次签出项目时在开发人员的本地运行,那么为什么需要对这些XML文件进行版本化? 当开发人员使用Check out from Version Control
创建项目时,Android Studio还会生成其余的/.idea
,那么为什么该文件夹中的任何内容都需要进行版本化?
如果*.iml
是版本化的,则新用户必须将项目命名为与提交时完全相同。 既然这也是一个生成的文件,为什么它首先出现呢?
local.properties
文件指向SDK的文件系统上的绝对路径,因此绝对不应对其进行版本控制。
编辑1 :添加.gradle
忽略不应该版本化的gradle缓存内容(感谢Vasily Makarov )。
编辑2 :添加.DS_Store
现在我正在使用Mac。 此文件夹是Mac特定的,不应进行版本控制。
附加说明 :您可能还希望在构建发布版本时添加一个目录以放置签名密钥。
复制/粘贴方便 :
.gradle
/build
/.idea
*.iml
local.properties
.DS_Store
我合并了Github .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
Please read: JetBrains Support: How to manage projects under Version Control Systems
我更喜欢添加.iml文件和Intellij sez来添加.idea文件夹但忽略.idea / workspace.xml和.idea / tasks.xml,但是.idea / libraries /?
我不知道添加它有多大意义。 它有一个XML文件列表,列出了Android Studio项目应该知道的库。 这些应该来自build.gradle定义的依赖项 - 而不是IDE项目文件。
其中一个文件的内容如下所示:
<component name="libraryTable">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.example/example/etc...jar!"/>
提交这个没有意义。 如果用户为gradle指定了不同的主目录,或者如果他们使用不同的gradle版本,那么.gradle/caches/artifacts-xxx
下的路径对他们来说会有所不同(即artifacts-
末尾附加的数字将是与你正在使用的gradle版本有关。)这些路径不是通用的,但建议是检查所有这些?
我用这个.gitignore。 我发现它在: http://th4t.net/android-studio-gitignore.html : http://th4t.net/android-studio-gitignore.html
*.iml
*.iws
*.ipr
.idea/
.gradle/
local.properties
*/build/
*~
*.swp
我知道这是一个古老的话题,肯定有很多选择,但我真的更喜欢Simon Whitaker的gibo
。 它使用起来非常简单,跨平台(mac,* nix和windows),并使用github github.com/github/gitignore repo,因此它(基本上)始终是最新的。
确保您的本地缓存是最新的:
$ gibo --upgrade
From https://github.com/github/gitignore
* branch master -> FETCH_HEAD
Current branch master is up to date.
搜索您需要的语言/技术:
$ gibo --search android
Android
显示.gitignore文件:
$ gibo Android
### Android
# 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
现在,将它附加到项目的.gitignore文件中:
$ gibo Android >> .gitignore
(确保使用>>
附加到项目的.gitignore文件;一个>
将覆盖它 - 因为我在事故中做了很多次!)
我知道这不是回答OP的确切问题,但是使用gibo使得你几乎不必再考虑“问题”了! .. 这真好! ;)
无需添加到源控件以下任何一项:
.idea/
.gradle/
*.iml
build/
local.properties
因此,您可以相应地配置hgignore或gitignore。
开发人员第一次克隆源控件时可以:
- 打开Android Studio
- 导入项目
- 浏览克隆的存储库中的build.gradle并将其打开
就这样
PS:Android Studio将通过maven获取gradle插件,假设您的build.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只需要build.gradle来导入项目并生成其余的项目。
这是通过这里生成.gitignore的最佳方式: http://www.gitignore.io/ : http://www.gitignore.io/
### 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