How to stop AndroidStudio from overwriting .idea/codeStyles/Project.xml
Asked Answered
A

1

29

In our project, we have committed .idea/codeStyles/Project.xml to source control with the goal of enforcing a common style among all contributors to the project without affecting the style of other projects.

However, Android Studio appears to be making unwanted changes to this file.

Pulling down the latest code from git and then simply opening Android Studio and then checking git status produces:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   my-project/.idea/codeStyles/Project.xml

no changes added to commit (use "git add" and/or "git commit -a")

The changes it is making look like this: enter image description here

As you can see it is removing some XML-formatting settings.

I am running Android Studio 3.5, but I can't guarantee that everyone else is, and we would like to keep the project agnostic with respect to IDE-version.

Is there a way to prevent Android Studio from changing these settings? Is there a more recommended way to achieve uniform code-style?

Amperehour answered 28/8, 2019 at 1:10 Comment(5)
Are these changes to the Project.xml causing changes in how your code is formatted? There's a chance the options that are removed from the config file are options where the configured value matches the default. In that case you should be good to commit the changes with no impact on your project.Beleaguer
I recommend going through and systematically disabling any non-standard / default plugins you may have loaded in Android Studio. In my case a plugin (Markdown Navigator Enhanced) was editing the Project.xml. Once I disabled that plugin for good, the file was no longer being modified. You may find options in the offending plugin you can play with to stop that behavior as well.Trull
We haven't added any plugins on top of what comes bundled with Android StudioAmperehour
@Trull thanks a lot, it was my case :) one of the installed plugins, Database Navigator, kept modifying the file. Disabling it fixed it.Fanchet
I have the same issue. It stoped for a while after reimporting the project but now it is at it again. I don't have any plugins.Nipa
A
0

ReadOnly or Unchangeable

Two solutions I can think are either to make the file read-only, or to mark it as unchangeable in git.

Note: Not sure if readOnly would crash GIT

git update-index --assume-unchanged .idea/codeStyles/Project.xml

To temporarily re-enable tracking:

git update-index --no-assume-unchanged .idea/codeStyles/Project.xml 

Another option

Another option is to add the specific file to your git ignore. Then have a daily script to pull/copy/download the latest updated copy of this config file into your folder.

I can imagine there are other options as well.

Antoniaantonie answered 3/6 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.