22

Android Code Style Guide defines "Android Code Style Rules".
To conform to these rules one have to change quite a number of settings of the Java Code Formatter (Window->Preferences->Java->Code Style->Formatter) default profile (in Eclipse IDE).

Did anyone manage to configure the formatter to follow the "Android Code Style Rules" already?
If yes, please export the Formatter profile and publish to be used by community.

PS: I've tried to do this myself but I've found that there are too many formatter options available, and most of them are not mentioned in the Code Style Guide :-(

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192
yvolk
  • 2,391
  • 3
  • 21
  • 26

5 Answers5

35

There are pre-made formatter rules available from the platform/development.git repository (GitHub mirror, in folder /ide/eclipse).

So you can simply import android-formatting.xml and android.importorder as mentioned here.

kroimon
  • 2,062
  • 3
  • 19
  • 23
  • Thank you, kroimon, very much! This is exactly what I was dreaming of :-) - these are "live" documents that continue improving as the Android ecosystem matures. – yvolk Mar 23 '10 at 10:26
  • So what are the new code style guidelines? Where can we find them? – Catalin Morosan Dec 06 '11 at 07:18
  • 3
    @kaciula The guidelines can now be found at: https://raw.github.com/android/platform_development/master/ide/eclipse/android-formatting.xml (https://github.com/android/platform_development/blob/master/ide/eclipse/) – karllindmark Mar 01 '12 at 12:31
  • Thank you, @ninetwozero. I just updated the answer with the latest links. – kroimon Mar 17 '12 at 21:22
6

On a related note, here's how developers around Google keep their various Eclipse instances all in agreement: Workspace Mechanic for Eclipse

Drew Dara-Abrams
  • 8,016
  • 11
  • 40
  • 48
1

I think personal or team preferences vary to much to globally enforce a coding style. So every body should deploy his project specific coding style.

Moritz
  • 10,124
  • 7
  • 51
  • 61
  • 2
    I agree, but it's much easier to start from the "globally enforced code style rules" and change them only in those areas that are really important to the person or team, comparing to starting from "as is" and then trying to figure out how far this state is from "globally inforced code style rules"?! – yvolk Mar 20 '10 at 13:24
  • I disagree. When people need to switch from one project to another, trying to read code which looks different can mess you up. Plus, there are some things that *nonone* should do really (like having two lines of an if statement without using curly braces) and you have to enforce these things to prevent possible logic bombs – the_new_mr Apr 25 '13 at 14:53
1

The link in kroimon's answer to android formatter rules is broken. Here is the correct one.

omermuhammed
  • 7,365
  • 4
  • 27
  • 40
1

Sync the source code according to these instructions. The formatting guidelines are in the file development/ide/eclipse/android-formatting.xml. You can import it with Eclipse.

Menu bar -> Window -> Preferences -> Java -> Code Style -> Formatter -> Import

Point it to the path of the android-formatting.xml

Viki
  • 19
  • 1