Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio writing BOM's to UTF-8 file

I am working on a project where all the source files are encoded as UTF-8, to please the java compiler (otherwis, 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.

like image 705
Machinarius Avatar asked Jun 17 '13 15:06

Machinarius


People also ask

How do I add BOM to UTF-8?

To Add BOM to a UTF-8 file, we can directly write Unicode \ufeff or three bytes 0xEF , 0xBB , 0xBF at the beginning of the UTF-8 file. The Unicode \ufeff represents 0xEF , 0xBB , 0xBF , read this. 1.1 The below example, write a BOM to a UTF-8 file /home/mkyong/file. txt .

How do I know if my BOM is UTF-8?

To check if BOM character exists, open the file in Notepad++ and look at the bottom right corner. If it says UTF-8-BOM then the file contains BOM character.


2 Answers

Remove BOM Didn't work for me.

It's the problem for the code I copied from a website.

I wrote it again and problem solved.

like image 145
Anice Jahanjoo Avatar answered Sep 19 '22 05:09

Anice Jahanjoo


It seems that this is a bug in IntellJ IDEA, on which Android Studio is based.

Try this:

  1. 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.)
  2. de-select "Autodetect UTF-encoded files"
  3. 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.

like image 43
free3dom Avatar answered Sep 23 '22 05:09

free3dom