什么文件应该在我的。gitignore为一个Android工作室项目?
我见过几个包含。iml的例子,但是IntelliJ文档说。iml必须包含在你的源代码控制中。
什么文件应该在我的。gitignore为一个Android工作室项目?
我见过几个包含。iml的例子,但是IntelliJ文档说。iml必须包含在你的源代码控制中。
当前回答
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
其他回答
我有忽略构建文件的问题,但这似乎是有效的:-)
# 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
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文件对其他开发人员和执行环境可用,您需要将它们检入版本控制。
我知道这是一个老话题,当然有很多选择,但我真的更喜欢西蒙惠特克的gibo。它使用起来超级简单,跨平台(mac, *nix和windows),并使用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使它使你几乎不必再考虑“问题”!. .很高兴!;)
在我正常的Android .gitignore的基础上,在阅读Intellij IDEA网站上的文档和阅读StackOverflow上的帖子后,我构建了以下文件:
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# built native files (uncomment if you build your own)
# *.o
# *.so
# generated files
bin/
gen/
# Ignore gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Eclipse Metadata
.metadata/
# Mac OS X clutter
*.DS_Store
# Windows clutter
Thumbs.db
# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
.idea/workspace.xml
.idea/tasks.xml
.idea/datasources.xml
.idea/dataSources.ids
还要注意,正如所指出的,当你用Android NDK构建自己的本机代码时,构建的本机文件部分主要是有用的。另一方面,如果您正在使用包含这些文件的第三方库,则可能希望删除这些行(*。O和*.so)来自你的。gitignore。
我支持提交。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