Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - "Unmappable character for encoding UTF-8"

All was working fine and dandy with Eclipse in Windows until I switched to Mac OS X Yosemite, using Android Studio V1.0. I imported the project as a Non-Android Studio project since it was created with Eclipse, the import went fine and then Android Studio started showing this error all over the files :

error : unmappable character for encoding UTF-8

EDIT: Opening files directly into Sublime Text show no errors in foreign characters. Using view.encoding() inside ST's console I was able to see the file encoding, which was Western (Windows 1252). I went to Android Studio and changed the encoding of the file to windows-1252 and it's now working fine !
Is there a way to tell Android Studio to read the files in windows-1252 and then convert them to UTF-8 to keep the standard encoding format ?

like image 869
Mehdiway Avatar asked Dec 17 '14 12:12

Mehdiway


People also ask

How do I resolve an Unmappable character for encoding UTF-8?

In eclipse try to go to file properties ( Alt + Enter ) and change the Resource → ' Text File encoding ' → Other to UTF-8 . Reopen the file and check there will be junk character somewhere in the string/file. Remove it. Save the file.

How do I fix the Unmappable character for encoding cp1252?

Go to common tab of RUN/DEBUG configuration in eclipse change encoding to UTF-8. Show activity on this post. Window > Preferences > General > Content Types, set UTF-8 as the default encoding for all content types. Window > Preferences > General > Workspace, set "Text file encoding" to "Other : UTF-8".

Can UTF-8 handle special characters?

Since ASCII bytes do not occur when encoding non-ASCII code points into UTF-8, UTF-8 is safe to use within most programming and document languages that interpret certain ASCII characters in a special way, such as / (slash) in filenames, \ (backslash) in escape sequences, and % in printf.

How do I change my UTF-8 character set?

Click Tools, then select Web options. Go to the Encoding tab. In the dropdown for Save this document as: choose Unicode (UTF-8). Click Ok.


2 Answers

Adding the following to build.gradle solves the problem :

android {
    ...
    compileOptions.encoding = 'ISO-8859-1'
like image 97
Mehdiway Avatar answered Sep 21 '22 22:09

Mehdiway


I have encountered this problem, too. The reason for my problem is that I copy a file which is not encoded UTF-8 from Eclipse to Android Studio. A solution to this problem is that:

  1. Make sure the default file encoding of your Android Studio is UTF-8: Settings --> File Encodings, set IDE Encoding, Project Encoding and Default encoding for properties files to UTF-8.
  2. Copy your error file to a txt file and delete the error file.
  3. Create a new file, its name is as the same as the deleted file.
  4. Copy the content from the txt file to the new file.
like image 37
Joybar Avatar answered Sep 22 '22 22:09

Joybar