AndroidSutdio "error": Could not correctly view external UTF8 line in debug or Android layout (Windows)

I cannot correctly view my UTF8 line in AndroidSutdio debugging or android layouts. below is my code:

        String test1 = "hélǐ";

Results: test1 = hà © lÇ

test1 It seems like reading my UTF8 ANSI encoded string in notepad ++. However, if I directly bind it to an XML layout (instead of the Button.setHint () method), I can correctly see hélǐ.

UPDATE 1: thanks Jon Skeet for pointing test1.lenght () = 6 and not 4, so this is not a display problem. UPDATE 2: thanks Joop Eggen for pointing out that “h \ u00e9l \ u012d” will return the correct answer UPDATE 3: I have a copy, paste my code into an equivalent Android project on eclipse and it works great. therefore, the problem should be related to AndroidStudio. UPDATE 4: added the variable JAVA_TOOL_OPTIONS = -Dfile.encoding = UTF-8 to force javac using this command, but without affecting the result. UPDATE 5: I installed AndroidStudio on ubuntu and copied my code, and it works fine too. But how to fix it on AndroidStudio Windows? (unfortunately, I need to use windows)

Has anyone ever encountered this problem before? how to fix without using code \ u Thanks

Note:

  • I am using AndroidStudio
  • in my Javac and Android DX complier I added -encoding utf8
  • in my AndroidStudio all file encodings are set to utf8 (and I see utf8 at the bottom right).
  • Charset.defaultCharset () return utf8
  • InputStreamReader.getEncoding () return utf8
  • In my xml layout there is a utf8 flag at the top
  • Notepad ++ reads my copy / paste "hélǐ" with utf8 encoding correctly.
+4
source share
3 answers

Fixed in the latest version of AndroidStudio

0
source
  • Try h\u00e9l\u012d too. This eliminates the java source encoding coefficient.
  • Try writing text to a file:

    new OutputStreamWriter (new FileOutputStream (file), "UTF-8")

Then the reason should be clearer.

Since the editor and compiler should use the same encoding, you seem to have done everything possible for the rest. It is especially checked with NotePad ++ (possibly also JEdit). One small point is the compilation of the IDE background and the final compilation.

The console also works: the console may mistakenly use the encoding of the operating system.

All of these new String(...) are supernatural and erroneous. Do not use this here, as indeed one error can cancel the error between the inconsistent encoding of the editor and the compiler.

(In ISO-8859-1, ĭ (i-breve) is not available - hence test3.)

+1
source

My case was exactly the same as that of Simon (I use Android Studio for Mac 0.2.2)

I solved the problem by editing the build.gradle file in the / src folder, adding the following lines:

 tasks.withType(Compile) { options.encoding = 'UTF-8' } 

It worked for me. Hope this helps someone with the same issue.

+1
source

Source: https://habr.com/ru/post/1482794/


All Articles