What should be in my .gitignore for an Android Stu

2018-12-31 08:06发布

What files should be in my .gitignore for an Android Studio project?

I've seen several examples that all include .iml but IntelliJ docs say that .iml must be included in your source control.

30条回答
刘海飞了
2楼-- · 2018-12-31 08:35

I use this .gitignore. I found it at: http://th4t.net/android-studio-gitignore.html

*.iml
*.iws
*.ipr
.idea/
.gradle/
local.properties

*/build/

*~
*.swp
查看更多
倾城一夜雪
3楼-- · 2018-12-31 08:35

My advise would be also to not ignore the .idea folder.

I've imported a Git-based Eclipse project to Android Studio and that went fine. Later, I wanted to import this project with Git (like the first time) to another machine with Android Studio, but that didn't worked. Android Studio did load all the files but wasn't able to "see" the project as a project. I only could open Git-files.

While importing the project for the first time (from Eclipse to Android Studio) my old .gitignore was overwritten and the new one looked like this:

  • .idea/.name
  • .idea/compiler.xml
  • .idea/copyright/profiles_settings.xml
  • .idea/encodings.xml
  • .idea/libraries/libs.xml
  • .idea/misc.xml
  • .idea/modules.xml
  • .idea/scopes/scope_settings.xml
  • .idea/vcs.xml
  • .idea/workspace.xml

So, I tried to use an empty gitignore and now it worked. The other Android Studio could load the files and the Project. I guess some files are not important (profiles_settings.xml) for Git and importing but I am just happy it worked.

查看更多
姐姐魅力值爆表
4楼-- · 2018-12-31 08:38

https://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
查看更多
只靠听说
5楼-- · 2018-12-31 08:38

I'm kosher with adding the .iml files and Intellij sez to add the .idea folder but ignore .idea/workspace.xml and .idea/tasks.xml, but what about .idea/libraries/ ?

I don't see how it makes sense to add this. It has a list of XML files that list libraries the Android Studio project is supposed to know about. These are supposed to come instead from build.gradle defined dependencies -- not an IDE project file.

Also the contents of one of these files looks like this:

<component name="libraryTable">
    <CLASSES>
       <root url="jar://$USER_HOME$/.gradle/caches/artifacts-26/filestore/com.example/example/etc...jar!"/>

It doesn't make sense to commit this. What if the user specified a different home dir for gradle, or if they use a different gradle version, the path under .gradle/caches/artifacts-xxx is going to be different for them (i.e. artifacts- the number appended on the end will relate to the gradle version release you are using.) These paths are not universal, and yet the advice is to check all this in?

查看更多
几人难应
6楼-- · 2018-12-31 08:39

Using the api provided by gitignore.io, you can get is automatically generated. Here is the direct-link also 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
.idea/assetWizardSettings.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
查看更多
无与为乐者.
7楼-- · 2018-12-31 08:39

There is NO NEED to add to the source control any of the following:

.idea/
.gradle/
*.iml
build/
local.properties

So you can configure hgignore or gitignore accordingly.

The first time a developer clones the source control can go:

  1. Open Android Studio
  2. Import Project
  3. Browse for the build.gradle within the cloned repository and open it

That's all

PS: Android Studio will then, through maven, get the gradle plugin assuming that your build.gradle looks similar to this:

// 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 will generate the content of .idea folder (including the workspace.xml, which shouldn't be in source control because it is generated) and the .gradle folder.

This approach is Eclipse-friendly in the way that the source control does not really know anything about Android Studio. Android Studio just needs the build.gradle to import a project and generate the rest.

查看更多
登录 后发表回答