Android unicode Cyrillic string turns to СЕ�ДВИЧ�Р� when passed in function

StackOverflow https://stackoverflow.com/questions/19038785

Question

I don't know if this is a Java problem or Android's one. But recently I have updated everything concerning my Android development setup.

So I upgraded

  • Java to 1.7_40 64 bit (i have 1.7_25 32 bit also installed),
  • Android studio to 0.2.10,
  • SDK tools to version 22.2.1,
  • SDK platform tools to version 18.0.1,
  • Gradle 1.7

And my android app started to behave very oddly. Before this update of my tools this line of code worked perfectly just like expected:

Category.getNew(1,"СЕНДВИЧАРА")

Now, on the other side of the get new function

public static Category getNew(int id, String name){
        Category result = new Category();
        result.setId(id);
        result.setName(name);
        return result;
}

for the name parameter I get this string СЕÐ�ДВИЧÐ�РÐ� which is not what I expected, I want my СЕНДВИЧАРА back, this string is passed along to the UI.

I can't let that cryptic string to be displayed on on the UI.

Please help.

Was it helpful?

Solution

Ok guys I found the solution by myself. And I'll post the answer here for future reference.

Apparently the cause of my problem was in Gradle. This is the first time I've been using it, by suggestion of Android Studio.

I have noticed that Gradle isn't very good in reporting problems during the building of the application, it displays them at random. At one moment while building the app I noticed this error:

Gradle: error: unmappable character for encoding Cp1252

This error looks like it was the cause of my problem. Quick google search and I bump into this article: Get rid of “unmappable character for encoding Cp1252″ once and for all which in summary says to add new Environment Variable named JAVA_TOOL_OPTIONS with value of -Dfile.encoding=UTF8 this way Java would always use UTF-8 as default encoding.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top