Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant encoding problem on Windows - UTF-8 files but spits garbage on diacritics

Tags:

Somehow I can't get my UTF-8 sources to play nice with Ant.

I get a whole lot of "warning: unmappable character for encoding ascii". I'm going crazy, really. Hours and hours and hours. Btw, I noticed 5 people already used the tag crazy. :-)

And yes, I've read this, this and others. Google also (the first 5 page results of at least 3 or 4 different searches, at least). There are javac options. I've tried. There is also some preset or something (sorry, 3 AM). Didn't work either.

I'm generating Android apk files with Ant. I can't use Eclipse, so no. And by the way, the ant documentation is gibberish to me. Those examples are of no use at all. I've lost count on how much I've tried.

I've tried using the Dfile.encoding option, tried mixing that with CHCP 65001 Windows command. Did all the combinations, and it even makes Ant (Javac I guess) stop spitting errors, but it still doesn't matter. My code still ends up with garbage carachters (a bunch of ?? instead of á, í etc).

like image 987
davidcesarino Avatar asked Nov 18 '10 05:11

davidcesarino


People also ask

Is UTF-8 the default encoding?

Fortunately UTF-8 is the default per sé. When reading an XML document and writing it in another encoding, mostly this attribute will be patched too.

What UTF-8 means?

UTF-8 (UCS Transformation Format 8) is the World Wide Web's most common character encoding. Each character is represented by one to four bytes. UTF-8 is backward-compatible with ASCII and can represent any standard Unicode character.


1 Answers

Are you specifying the file encoding to the compiler correctly? The java compiler will otherwise default to use the platform's default encoding, which on Windows (for example) is not UTF-8. The encoding is specified by using the -encoding flag to javac.

javac -encoding utf8 ... 

And in ant build.xml:

<javac ... encoding="UTF-8" ... /> 
like image 150
JesperE Avatar answered Oct 07 '22 14:10

JesperE