I am working on a project where all the source files are encoded as UTF-8 so as to please the java compiler (It will spit out errors on other encodings). Everytime i save a source file with Android Studio, it will write a Byte Order Mark on the file, preventing the compilation from succeeding. How can i fix this?
As a workaround, i am manually deleting the BOM with a Hex Editor but it gets really annoying.
It seems that this is a bug in IntellJ IDEA, on which Android Studio is based.
Try this:
- In Settings | File Encodings Select the "Projekt"-Entry with the mouse in the second column and choose "" (Confrim removal of Encodings set in subdirectories or choose the directories where you don't wan't a default-encoding enforced.)
- de-select "Autodetect UTF-encoded files"
- select "Transparent native-to-ascii conversion"
(Reference for above)
Another possible fix is to remove all BOMs outside Android studio (with hex editor or another text editor) and then choosing File -> Synchronize
in AS.
You can use some tool to convert your file to UTF-8 with BOM.
I used Notepad++:
- remove "
<?xml version="1.0" encoding="utf-8"?>
" from file if it is. (I used Notepad for that)
- open file with Notepad++.
- ensure you see characters as they should be
- select Menu -> Encoding -> Convert to UTF-8
- add "
<?xml version="1.0" encoding="utf-8"?>
" at file start
In Android Studio "Project" pane, right-click on the file with BOM problem(s) and select: Analyze > Inspect Code.
Then click OK.
You will get a list of all BOM errors in the file. You can right-click on each error and select to remove the BOM.