3

I have a strange problem. I'm using a Windows laptop and a Mac Air for Android development. I use Eclipse as IDE in both of them, Git and GitHub for source code control, and EGit plugin for Eclipse.
Sometimes I use non-English (in fact, Russian) language for comments. And here some strange things occur: when I'm working on Windows, add a comment in non-English, save the source code file, commit the changes, and open it on Mac, that files goes in gibberish (some problems with encoding). When I do vice versa (work on Mac, add comments in non-English, save file, commit changes, open on Windows), everything is displayed fine.
Why do such strange things take place? Why there is a difference with encodings?

3
  • 1
    What settings are you using in Eclipse for your files? I'd recommend using UTF-8 (and the same on both!)
    – Jon Skeet
    Oct 8, 2013 at 14:57
  • If I had to guess, I'd say that in windows it's being encoded using windows-1251 and on your mac it's being encoded with UTF-8.
    – Aurand
    Oct 8, 2013 at 14:58
  • Where can I find settings in Eclipse for saving my files? I thought that Eclipse saves everything in UTF-8 by default... Oct 8, 2013 at 15:08

1 Answer 1

9

Eclipse uses the platform default encoding by default. These are different between Windows, Mac OS X and Linux.

It is recommended to configure this on the project. Do the following:

  1. Open project properties (context menu on project > Properties)
  2. Go to the Resource tab
  3. Change Text file encoding from Inherited from container to Other and select UTF-8 (the only sane choice really)
  4. Commit the resulting changes in file .settings/org.eclipse.core.resources.prefs

The last step ensures that the encoding used by Eclipse for this project will always be the same, regardless of platform or workspace settings.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.