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.
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 .
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.
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.
It seems that this is a bug in IntellJ IDEA, on which Android Studio is based.
Try this:
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With