android studio bom,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.

free3dom

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"

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.

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.

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

If you are using Android Studio 3.3.1

Just right-click on the file, from the menu you will find Remove BOM

for Android studio 3.4 Right Click on Android Project. List will pop up, below the list you will see No BOM, click on it and then run the project. encoding byte error issue will resolved

来源:https://stackoverflow.com/questions/17151830/android-studio-writing-boms-to-utf-8-file

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值