Which files should I track with git in Android Studio? [duplicate] - android

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.

Updated to Android Studio 3.0
Please share missing items in comments.
A late answer but this alternative answer was not right for us ...
So, here's our gitignore file:
#built application files
*.apk
*.ap_
*.aab
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/
.navigation
captures/
output.json
#NDK
obj/
.externalNativeBuild
Since Android Studio 2.2 and up to 3.0, new projects are created with this gitignore file:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
Deprecated - for older project format, add this section to your gitignore file:
/*/out
/*/*/build
/*/*/production
*.iws
*.ipr
*~
*.swp
This file should be located in the project's root folder and not inside the project's module folder.
Edit Notes:
Since version 0.3+ it seems you can commit and push *.iml and build.gradle files. If your project is based on Gradle: in the new open/import dialog, you should check the "use auto import" checkbox and mark the "use default gradle wrapper (recommended)" radio button. All paths are now relative as #George suggested.
Updated answer according to #128KB attached source and #Skela suggestions

Building on my normal Android .gitignore, and after reading through documentation on the Intellij IDEA website and reading posts on StackOverflow, I have constructed the following file:
# 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
Also note that as pointed out, the built native files section is primarily useful when you are building your own native code with the Android NDK. If, on the other hand, you are using a third party library that includes these files, you may wish to remove these lines (*.o and *.so) from your .gitignore.

Updated 7/2015:
Here is the definitive source from JetBrains
Directory based project format (.idea directory)
This format is used by all the recent IDE versions by default. Here is what you need to share:
All the files under .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings
All the .iml module files that can be located in different module directories (applies to IntelliJ IDEA)
Be careful about sharing the following:
Android artifacts that produce a signed build (will contain keystore passwords)
In IDEA 13 and earlier dataSources.ids, datasources.xml can contain database passwords. IDEA 14 solves this problem.
You may consider not to share the following:
gradle.xml file, see this discussion
user dictionaries folder (to avoid conflicts if other developer has the same name)
XML files under .idea/libraries in case they are generated from Gradle project
Legacy project format (.ipr/.iml/.iws files)
Share the project .ipr file and all the .iml module files, don't share the .iws file as it stores user specific settings
While these instructions are for IntelliJ IDEA, they hold true 100% for Android Studio.
Here is a .gitignore snippet that incorporates all of the above rules:
# Android Studio / IntelliJ IDEA
*.iws
.idea/libraries
.idea/tasks.xml
.idea/vcs.xml
.idea/workspace.xml

I disagree with all of these answers. The following configuration is working great for our organization's app.
I ignore:
/build
/.idea (with possible exceptions, see comments in dalewking's answer)
*.iml
local.properties
I think almost everyone agrees about /build.
I got sick of constantly seeing messages about the various library.xml files that Gradle creates or deletes in /.idea. The build.gradle will run on the developers's local when they first check out the project, so why do those XML files need to be versioned? Android Studio will also generate the rest of /.idea when a developer creates a project using Check out from Version Control, so why does anything in that folder need to be versioned?
If the *.iml is versioned a new user will have to name the project exactly the same as it was when committed. Since this is also a generated file, why version it in the first place?
The local.properties files points to an absolute path on the file system for the SDK, so it definitely shouldn't be versioned.
Edit 1: Added .gradle to ignore the gradle caching stuff that should not be versioned (thanks Vasily Makarov).
Edit 2: Added .DS_Store now that I am using Mac. This folder is Mac specific and should not be versioned.
Additional note: You probably also want to add a directory to put your signing keys in when building a release version.
For copy/paste convenience:
.gradle
/build
/.idea
*.iml
local.properties
.DS_Store

Android Studio Chipmunk 2021.2.1
If you create a Gradle project using Android Studio the .gitignore file will contain the following:
.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
I would recommend ignoring the complete ".idea" directory because it contains user-specific configurations, nothing important for the build process.
Gradle project folder
The only thing that should be in your (Gradle) project folder after repository cloning is this structure (at least for the use cases I encountered so far):
app/
.git/
gradle/
build.gradle
.gitignore
gradle.properties
gradlew
gradlew.bat
settings.gradle
Note: It is recommended to check-in the gradle wrapper scripts (gradlew, gradlew.bat) as described here.
To make the Wrapper files available to other developers and execution environments you’ll need to check them into version control.

I use this .gitignore. I found it at: http://th4t.net/android-studio-gitignore.html
*.iml
*.iws
*.ipr
.idea/
.gradle/
local.properties
*/build/
*~
*.swp

In the case of Android Studio, the only files that are required to be saved in version control are the files required to build the application from the command line using gradle. So you can ignore:
*.iml
.idea
build
However, if you save any IDE settings, such as custom code style settings, they get saved in the .idea folder. If you want those changes in version control, then you'd save the IDEA files as well (*.iml and .idea).

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.

It's the best way to generate .gitignore via here

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:
Open Android Studio
Import Project
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.

I support the committing of .idea folder (excluding workspace.xml and tasks.xml). But I am starting to come to the conclusion that .iml files should be ignored.
Here is the issue:
Open a project in a directory named "foo" for example and you will get foo.iml and that all seems well and good. The problem is that if I simply rename the directory to foo2 (or clone it into another directory name) when you try to open the project in Android Studio you will get three things:
A new iml file named foo2.iml
The iml file for your Android project will be changed to point now to foo2 as its parent
.idea/modules.xml will have a line added for foo2.iml so it has both the old iml file and the one for the new directory
I can find no way to prevent Android Studio from doing this iml file generation when the project is stored in a different directory. Adding them to source control is going to cause problems. Therefore I think perhaps we should ignore *.iml files and .idea/modules.xml

Tested with Android Studio 3.0
You might need to Install .ignore plugin.
You can auto-generate the .gitignore file for Android.
Right click on folder and follow
Then Select Android from left panel and click Generate
Android Studio will generate .gitignore file which contains all the file need to ignore.
Taken from http://menukanows.com/how-to-add-gitignore-file-in-android-project/

Depends on how your project format is maintained:
You have two options:
Directory-based format (You will have a .idea folder which contains
the project specific files)
File-based format (configuration files are .iws and .ipr)
Ref:
http://www.jetbrains.com/idea/webhelp/project.html
Files committed to version control depends on the above:
Include .idea folder to version control, exclude workspace.xml and
tasks.xml
Version control .ipr file and all the .iml module files, exclude
the .iws file as it stores user specific settings.
Ref:
https://intellij-support.jetbrains.com/entries/23393067

Basically any file that is automatically regenerated.
A good test is to clone your repo and see if Android Studio is able to interpret and run your project immediately (generating what is missing).
If not, find what is missing, and make sure it isn't ignored, but added to the repo.
That being said, you can take example on existing .gitignore files, like the Android one.
# 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/

As of Android Studio 0.8.4 .gitignore file is generated automatically when starting new project.
By default it contains:
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build

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?

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

I know this is an old topic and there are certainly a lot of options, but I really prefer gibo by Simon Whitaker. It's super simple to use, cross-platform (mac, *nix, and windows), and uses the github gitignore repo so it is (basically) always up to date.
Make sure your local cache is up to date:
$ gibo --upgrade
From https://github.com/github/gitignore
* branch master -> FETCH_HEAD
Current branch master is up to date.
Search for the language/technology you need:
$ gibo --search android
Android
Display the .gitignore file:
$ 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
Now, append it to your project's .gitignore file:
$ gibo Android >> .gitignore
(Make sure you use >> to append to your project's .gitignore file; one > will overwrite it - as I've done many times on accident!)
I know this isn't answering the OP's exact question, but using gibo makes it so you pretty much don't have to think about 'the question' anymore! .. it's nice! ;)

To get a better idea, all you need are the following files
app
build.gradle
settings.gradle
You could put everything else in the .gitignore file. All your app changes lies mostly in these files and folders. The rest you see in a basic project are gradle build files or Android Studio configuration files.
If you are using Android Studio, you can use "Import project" to successfully build the project. Alternatively you can build using command line, follow Building Android Projects with Gradle.

It's best to add up the .gitignore list through the development time to prevent unknown side effect when Version Control won't work for some reason because of the pre-defined (copy/paste) list from somewhere. For one of my project, the ignore list is only of:
.gradle
.idea
libs
obj
build
*.log

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
Android Gitignore in github

I merge Github .gitignore files
Android.gitignore
JetBrains.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

As of Android Studio 0.8.4 .gitignore file is generated automatically when starting new project. By default it contains:
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
build/
/captures
I agree with this statement, however I modify this file to change
/build to build/
(This will include /build and /app/build)
So I don't end up with all the files in app/build in my repository.
Note also that if you import a project from Eclipse, the .gitignore won't be copied, or "automagically" created for you.

Android Studio 3.5.3
I use this for my libraries and projects and it covers most of the files that generate by android studio and other famous tools:
# 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

This is created using the reference of http://gitignore.io/ Where you can create the latest updated gitignore file for any project. For Android http://gitignore.io/api/androidstudio. Hope this helps. Currently I am using Android Studio 3.6.3
# Created by https://www.gitignore.io/api/androidstudio
# Edit at https://www.gitignore.io/?templates=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

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/

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

This official documentation from JetBrains Support says the following should be included:
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
It also gives other recommendations of things to be careful about.

.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

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

Related

Git ignoring Android Studio project libs folder

In my current project, I've added a libs folder inside my project's app directory. inside the libs, I've added an SDK in .aar format. But currently, the problem is that, when I push all my updates into a git repo, all of my updates pushed perfectly, except that libs folder. But I need to push that libs folder to the git repo. How I will able to do that. Here is my .gitignore file -
# Built application files
*.apk
*.aar
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/
# 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/misc.xml
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
.idea/
# 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
.cxx/
# 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
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
What should I do now to resolve this issue?
You can try:
git add --force <path_to_libs>
or add in .gitignore:
!<path_to_libs>
the "!" makes git do not ignore libs, as by default it is ignoring.
And how exactly is that .gitignore file related to Android Studio ??
The only way to provide a local AAR dependency is a local flatDir repository.

How to make sure .gitignore works for multiple Android projects in the same repository

My problem is similar to the one outlined in this post, but the solution did not help. I essentially have one Github repository with a whole bunch of different folders/directories that each contain a separate Android project.
The structure of one such project looks like MyTeamRepo -> MyAndroidProject -> app
Normally if it was just a single Android project, throwing the .gitignore in the /gradle directory would work, but it's not working out in my case.
Here's what's currently in my .gitignore:
# Built application files
*.apk
*.ap_
*.aab
# 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/misc.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
# Android Studio 3 in .gitignore file.
.idea/caches/build_file_checksums.ser
.idea/modules.xml
# 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
# 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
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
lint/reports/
My problem is I still keep having these .idea and .gradle files popping up everywhere within the subfolders every time I make any changes to the Android project, causing all sorts of merge conflicts when I try to pull changes from Github.
I also think part of the problem is that the .idea had previously been committed to Github and now I am always tracking it.
What steps do I need to take to completely clean my repository and to make sure the .gitignore is doing its job?
If you want to ignore a file anywhere in the tree use something like
**/.idea/modules.xml
and no matter where the .idea directory is that the modules.xml file will be ignored.

which files to ignore using to commit to SVN in eclipse

I have used Eclipse and SVN for a while. However, I'm still not clear which files/folders usually should be ignored while commit the whole project to repository. I know .project needs to be ignored. What about others? By the way this is an android project. However, answers to general project are also welcome.
Thanks.
We are using configuration as below to support different IDE:
# Eclipse related (and M2e)
.classpath
.project
.settings/
.metadata/
test-output/
# Maven related (and some plugins)
target/
*~
dist
*.ser
*.ec
# Intellij
*.ipr
*.iml
*.iws
.idea
.temp
# Other
.svn/
bin/
bak/
*.log
*.orig
*.versionsBackup
Basically following list of files added in .gitignore file for android projects.
# 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/

Files to ignore while using Android Studio with Git or Mercurial [duplicate]

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.
Updated to Android Studio 3.0
Please share missing items in comments.
A late answer but this alternative answer was not right for us ...
So, here's our gitignore file:
#built application files
*.apk
*.ap_
*.aab
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Android Studio
*.iml
.idea
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
.gradle
build/
.navigation
captures/
output.json
#NDK
obj/
.externalNativeBuild
Since Android Studio 2.2 and up to 3.0, new projects are created with this gitignore file:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
Deprecated - for older project format, add this section to your gitignore file:
/*/out
/*/*/build
/*/*/production
*.iws
*.ipr
*~
*.swp
This file should be located in the project's root folder and not inside the project's module folder.
Edit Notes:
Since version 0.3+ it seems you can commit and push *.iml and build.gradle files. If your project is based on Gradle: in the new open/import dialog, you should check the "use auto import" checkbox and mark the "use default gradle wrapper (recommended)" radio button. All paths are now relative as #George suggested.
Updated answer according to #128KB attached source and #Skela suggestions
Building on my normal Android .gitignore, and after reading through documentation on the Intellij IDEA website and reading posts on StackOverflow, I have constructed the following file:
# 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
Also note that as pointed out, the built native files section is primarily useful when you are building your own native code with the Android NDK. If, on the other hand, you are using a third party library that includes these files, you may wish to remove these lines (*.o and *.so) from your .gitignore.
Updated 7/2015:
Here is the definitive source from JetBrains
Directory based project format (.idea directory)
This format is used by all the recent IDE versions by default. Here is what you need to share:
All the files under .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings
All the .iml module files that can be located in different module directories (applies to IntelliJ IDEA)
Be careful about sharing the following:
Android artifacts that produce a signed build (will contain keystore passwords)
In IDEA 13 and earlier dataSources.ids, datasources.xml can contain database passwords. IDEA 14 solves this problem.
You may consider not to share the following:
gradle.xml file, see this discussion
user dictionaries folder (to avoid conflicts if other developer has the same name)
XML files under .idea/libraries in case they are generated from Gradle project
Legacy project format (.ipr/.iml/.iws files)
Share the project .ipr file and all the .iml module files, don't share the .iws file as it stores user specific settings
While these instructions are for IntelliJ IDEA, they hold true 100% for Android Studio.
Here is a .gitignore snippet that incorporates all of the above rules:
# Android Studio / IntelliJ IDEA
*.iws
.idea/libraries
.idea/tasks.xml
.idea/vcs.xml
.idea/workspace.xml
I disagree with all of these answers. The following configuration is working great for our organization's app.
I ignore:
/build
/.idea (with possible exceptions, see comments in dalewking's answer)
*.iml
local.properties
I think almost everyone agrees about /build.
I got sick of constantly seeing messages about the various library.xml files that Gradle creates or deletes in /.idea. The build.gradle will run on the developers's local when they first check out the project, so why do those XML files need to be versioned? Android Studio will also generate the rest of /.idea when a developer creates a project using Check out from Version Control, so why does anything in that folder need to be versioned?
If the *.iml is versioned a new user will have to name the project exactly the same as it was when committed. Since this is also a generated file, why version it in the first place?
The local.properties files points to an absolute path on the file system for the SDK, so it definitely shouldn't be versioned.
Edit 1: Added .gradle to ignore the gradle caching stuff that should not be versioned (thanks Vasily Makarov).
Edit 2: Added .DS_Store now that I am using Mac. This folder is Mac specific and should not be versioned.
Additional note: You probably also want to add a directory to put your signing keys in when building a release version.
For copy/paste convenience:
.gradle
/build
/.idea
*.iml
local.properties
.DS_Store
Android Studio Chipmunk 2021.2.1
If you create a Gradle project using Android Studio the .gitignore file will contain the following:
.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
I would recommend ignoring the complete ".idea" directory because it contains user-specific configurations, nothing important for the build process.
Gradle project folder
The only thing that should be in your (Gradle) project folder after repository cloning is this structure (at least for the use cases I encountered so far):
app/
.git/
gradle/
build.gradle
.gitignore
gradle.properties
gradlew
gradlew.bat
settings.gradle
Note: It is recommended to check-in the gradle wrapper scripts (gradlew, gradlew.bat) as described here.
To make the Wrapper files available to other developers and execution environments you’ll need to check them into version control.
I use this .gitignore. I found it at: http://th4t.net/android-studio-gitignore.html
*.iml
*.iws
*.ipr
.idea/
.gradle/
local.properties
*/build/
*~
*.swp
In the case of Android Studio, the only files that are required to be saved in version control are the files required to build the application from the command line using gradle. So you can ignore:
*.iml
.idea
build
However, if you save any IDE settings, such as custom code style settings, they get saved in the .idea folder. If you want those changes in version control, then you'd save the IDEA files as well (*.iml and .idea).
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.
It's the best way to generate .gitignore via here
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:
Open Android Studio
Import Project
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.
I support the committing of .idea folder (excluding workspace.xml and tasks.xml). But I am starting to come to the conclusion that .iml files should be ignored.
Here is the issue:
Open a project in a directory named "foo" for example and you will get foo.iml and that all seems well and good. The problem is that if I simply rename the directory to foo2 (or clone it into another directory name) when you try to open the project in Android Studio you will get three things:
A new iml file named foo2.iml
The iml file for your Android project will be changed to point now to foo2 as its parent
.idea/modules.xml will have a line added for foo2.iml so it has both the old iml file and the one for the new directory
I can find no way to prevent Android Studio from doing this iml file generation when the project is stored in a different directory. Adding them to source control is going to cause problems. Therefore I think perhaps we should ignore *.iml files and .idea/modules.xml
Tested with Android Studio 3.0
You might need to Install .ignore plugin.
You can auto-generate the .gitignore file for Android.
Right click on folder and follow
Then Select Android from left panel and click Generate
Android Studio will generate .gitignore file which contains all the file need to ignore.
Taken from http://menukanows.com/how-to-add-gitignore-file-in-android-project/
Depends on how your project format is maintained:
You have two options:
Directory-based format (You will have a .idea folder which contains
the project specific files)
File-based format (configuration files are .iws and .ipr)
Ref:
http://www.jetbrains.com/idea/webhelp/project.html
Files committed to version control depends on the above:
Include .idea folder to version control, exclude workspace.xml and
tasks.xml
Version control .ipr file and all the .iml module files, exclude
the .iws file as it stores user specific settings.
Ref:
https://intellij-support.jetbrains.com/entries/23393067
Basically any file that is automatically regenerated.
A good test is to clone your repo and see if Android Studio is able to interpret and run your project immediately (generating what is missing).
If not, find what is missing, and make sure it isn't ignored, but added to the repo.
That being said, you can take example on existing .gitignore files, like the Android one.
# 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/
As of Android Studio 0.8.4 .gitignore file is generated automatically when starting new project.
By default it contains:
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
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?
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
I know this is an old topic and there are certainly a lot of options, but I really prefer gibo by Simon Whitaker. It's super simple to use, cross-platform (mac, *nix, and windows), and uses the github gitignore repo so it is (basically) always up to date.
Make sure your local cache is up to date:
$ gibo --upgrade
From https://github.com/github/gitignore
* branch master -> FETCH_HEAD
Current branch master is up to date.
Search for the language/technology you need:
$ gibo --search android
Android
Display the .gitignore file:
$ 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
Now, append it to your project's .gitignore file:
$ gibo Android >> .gitignore
(Make sure you use >> to append to your project's .gitignore file; one > will overwrite it - as I've done many times on accident!)
I know this isn't answering the OP's exact question, but using gibo makes it so you pretty much don't have to think about 'the question' anymore! .. it's nice! ;)
To get a better idea, all you need are the following files
app
build.gradle
settings.gradle
You could put everything else in the .gitignore file. All your app changes lies mostly in these files and folders. The rest you see in a basic project are gradle build files or Android Studio configuration files.
If you are using Android Studio, you can use "Import project" to successfully build the project. Alternatively you can build using command line, follow Building Android Projects with Gradle.
It's best to add up the .gitignore list through the development time to prevent unknown side effect when Version Control won't work for some reason because of the pre-defined (copy/paste) list from somewhere. For one of my project, the ignore list is only of:
.gradle
.idea
libs
obj
build
*.log
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
Android Gitignore in github
I merge Github .gitignore files
Android.gitignore
JetBrains.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
As of Android Studio 0.8.4 .gitignore file is generated automatically when starting new project. By default it contains:
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
build/
/captures
I agree with this statement, however I modify this file to change
/build to build/
(This will include /build and /app/build)
So I don't end up with all the files in app/build in my repository.
Note also that if you import a project from Eclipse, the .gitignore won't be copied, or "automagically" created for you.
Android Studio 3.5.3
I use this for my libraries and projects and it covers most of the files that generate by android studio and other famous tools:
# 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
This is created using the reference of http://gitignore.io/ Where you can create the latest updated gitignore file for any project. For Android http://gitignore.io/api/androidstudio. Hope this helps. Currently I am using Android Studio 3.6.3
# Created by https://www.gitignore.io/api/androidstudio
# Edit at https://www.gitignore.io/?templates=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
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/
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
This official documentation from JetBrains Support says the following should be included:
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
It also gives other recommendations of things to be careful about.
.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
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

In Android development, what files should be committed to a repository?

Which files in an Android project should be committed to a version control repository? Which files should not be committed?
Right now my .gitignore file consists of the following lines:
# Android generated files #
###########################
android.keystore
local.properties
bin/
gen/
libs/
obj/
# OS generated files #
######################
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
# Eclipse generated files #
###########################
.settings/org.eclipse.jdt.core.prefs
Am I missing anything?
GitHub maintains an official list of recommended .gitignore files at this public repository.
For Android you can find it here
Or just copy/paste :
# Built application files
*.apk
*.aar
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Uncomment the following line in case you need and you don't have the release build type files in your app
# release/
# 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
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml
# 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
.cxx/
# 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
# Version control
vcs.xml
# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
The general rule of thumb is to not commit any file that can be re-generated, into the repository. Having said that, you may want to add your project.properties file to .gitignore as well (if it exists).
don't add bin folder and gen folder. They are not part of your sources they are generated. In future remember that you add only files necessary to build and run your project, and binary and generated files are not.
Yet if you're not using any tool like ivy or maven you may want your lib folder to present. Often when you use a library project, you also need to commit it
As of Android Studio 2.2.2 (and was probably added well before this version) when you create a new project, Google add a default .gitignore file to the project for you with the following contents:
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
A little different from the above answers, as it also ignores the .idea folders, which tend to have a lot of files in them.
Using darcs, one adds the tracked files explicitly, rather than excluding them with an ignore file. After creating the new android project, I recorded my initial commit with all .java, .xml, .gradle, .properties, and .webp files added, except for local.properties.
This command did that:
( fd .*.java & fd .*.xml & fd .*.gradle & fd .*.properties & fd .*.webp; )
| cat
| rg -v ^local.properties
| xargs -I {} darcs add {}

Categories

Resources