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. Hou
You should set the same page in many places:
javac encoding="UTF-8" ... /
-Dfile.encoding=UTF-8
in parameters of Ant callingIn file-properties-resource-encoding - again choose the same page. You can also change it for all files in the container by the IDE (preferences for Eclipse). Then make all files to inherit it from the container.
If some files were created in wrong encoding, rework their content through PsPad or maybe, another text editor (copy-paste, change file encoding, back copy-paste). These files will be mentioned in unmappable character
errors.
After setting all these four problems you will have NO unmappable character
lines.
Just specify encoding in your build.xml
script:
<javac encoding="UTF-8" ... />
But for code re-use it's better to extract value into project-specific configuration file:
<property file="build.properties" />
<property name="java.encoding" value="ascii" />
<javac encoding="${java.encoding}"
source="${java.source}" ....>
<src path="${source.dir}" />
<classpath>
<fileset ... />
</classpath>
</javac>
And then just add java.encoding=UTF-8
to build.properties to override encoding on per-project basis.
below is the usage of -Dfile.encoding=UTF-8 in ant build.xml file:
<java classname="${main-class}" fork="true">
<jvmarg value="-Dfile.encoding=UTF-8"/>
This will solve the problem. Working for all UTF 8 char's.
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" ... />
To all you who use UTF-8 source files on Windows and was trying to build Android packages with Proguard using the famous blog post by Dan Galpin/Tim Bray.
This encoding problem happens with javac (thanks for the tip, JesperE). However, I was unable to create a new javac rule on my project's files, because of needed parameters that I didn't know anything about. So here is the easy answer (probably not the only answer):
Notice that, on the start, there is an output talking about some imported ANT rules. Right on the start you will see some [setup] rules. Look for this one:
[setup] Importing rules file: tools\ant\ant_rules_r3.xml
Find that file and open it. Search for "javac encoding". You will see that is set to "ascii". Change to "UTF-8".
That's how I did here. I'm sure there is a way to override this on a per-project basis. But it kept giving me errors on mandatory parameters, as I said. So for me at least it was that much easier doing this way. Besides, I only work with UTF-8 anyway.