Sync Project settings using VCS

The first step is to remove the .idea folder as a whole from the VCS exclusions and add more fine-grained rules. Most people use Git, so that’s what the examples will be using. In your root .gitignore file, make sure you don’t have an entry that looks like this:

/.idea/*

Applying all the JetBrains’ recommendations from before, and after some battle-testing, I ended up with this set of rules for the .gitignore that seems to cover all our needs (and more!):

# IDEA/Android Studio Ignore exceptions

!/.idea/vcs.xml

!/.idea/fileTemplates/

!/.idea/inspectionProfiles/

!/.idea/scopes/

!/.idea/codeStyleSettings.xml

!/.idea/encodings.xml

!/.idea/copyright/

!/.idea/compiler.xml

Commit that. Now, open the preferences (Cmd-, on a Mac, Ctrl-Alt-S elsewhere), and navigate to the Code style section. Then click the Manage button:

Note how the screen says “for current project”, we’ll get to it later

In the dialog that opens, pick the scheme to use as a base — it will be Default unless you have something like Novoda’s shared scheme — and click Copy to Project.

Congratulations! Now you have a bunch of “new” files in your .idea folder. Those files have rather self-explainatory names. The most important ones are of course codeStyleSettings.xml and the contents of fileTemplates. Note that these files/folders will only appear when your settings are different from the default schema’s.

That’s really all you need to do. Once you commit them, everyone that picks them up should be up and running with the shared settings. Anything that shows up in the preferences screen and in other places with the small icon that looks like a copy icon (two overlapping sheets of paper) can be part of the shared settings:

Just some of the things you can share

A couple of caveats

You might want to check that people isn’t using overridden settings themselves, when you first roll the project settings out. In that case, the IDE might override the settings coming from VCS. I’m not sure this is intended behaviour — it seems weird to me, but it’s easy enough to check.

Another small note is that you want to keep your additional plugins in check. Some plugins tend to write their own settings, and that should be fine, but the problem is that a bug (marked as resolved, but it’s probably a regression) in the IDE causes “unknown” code style nodes to be removed instead of ignored. This means you have to make sure the team is aligned on which plugins to have enabled in the IDE while working on the project.