64

After importing my project from eclipse into android studio i have got the following error :

Error: unmappable character for encoding UTF-8

Android Studio : 0.5.8

10 Answers 10

136

I had the same problem because there was files with windows-1251 encoding and Cyrillic comments. In Android Studio which is based on IntelliJ IDEA you can solve it in two ways:

a) convert file encoding to UTF-8 or

b) set the right file encoding in your build.gradle script:

android {
    ...
    compileOptions.encoding = 'windows-1251' // write your encoding here
    ...

To convert file encoding use the menu at the bottom right corner of IDE. Select right file encoding first -> press Reload -> select UTF-8 -> press Convert.

Also read this Use the UTF-8, Luke! File Encodings in IntelliJ IDEA

5
  • 1
    Thank you sir. I was having up to 100 errors when building due to spanish javadoc.
    – Alberto
    Commented Nov 17, 2014 at 23:33
  • ~"left lower corner of IDE". What do you mean? Do you have a screenshot of that button? Commented Mar 11, 2015 at 20:54
  • 2
    @IgorGanapolsky please click on the link in my answer. There are many interesting screenshots.
    – mrblrrd
    Commented Mar 18, 2015 at 7:10
  • "To convert file encoding use the menu at the bottom right corner of IDE. Select right file encoding first -> press Reload -> select UTF-8 -> press Convert" helped me, thank you.
    – Michal
    Commented Jun 5, 2015 at 13:11
  • Remember to change your encoding in both build.gradle and your file. Commented Jun 5, 2015 at 14:06
13

Adding the following to build.gradle solves the problem :

android {
 ...
compileOptions.encoding = 'ISO-8859-1'
 }
12

1/ Convert the file encoding
File -> Settings -> Editor -> File encodings -> set UTF-8 for

  • IDE Encoding
  • Project Encoding
  • Default encoding propertie file

Press OK

2/ Rebuild Project

Build -> Rebuild project

5

I have the problem with encoding in javadoc generated by intellij idea. The solution is to add

-encoding UTF-8 -docencoding utf-8 -charset utf-8

into command line arguments!

UPDATE: more information about compilation Javadoc in Intellij IDEA see in my post

2

Add system variable (for Windows) "JAVA_TOOL_OPTIONS" = "-Dfile.encoding=UTF8".

I did it only way to fix this error.

1

In Android Studio resolved it by

  1. Navigate to File > Editor > File Encodings.
  2. In global encoding set the encoding to ISO-8859-1
  3. In Project encoding set the encoding to UTF-8 and the same case to Default encoding for properties files.
  4. Rebuild project.
0

A few encoding issues that I had to face couldn't be solved by above solutions. I had to either update my Android Studio or run test cases using following command in the AS terminal.

gradlew clean assembleDebug testDebug

P.S your encoding settings for IDE and project should match.

Hope it helps !

0

If above answeres did not work, then you can try my answer because it worked for me.
Here's what worked for me.

  1. Close Android Studio
  2. Go to C:\Usersyour username
  3. Locate the Android Studio settings directory named .AndroidStudioX.X (X.X being the version)
  4. C:\Users\my_user_name.AndroidStudio4.0\system\caches
  5. Delete the caches folder and open android studio

This should fix the issue.

0

Check all 'C' characters. There are may be some cyrillic 'C's in english-looking word.
Reason for this is that in both english and russian keyboards 'C' occupies same physical button.

0

A different approach to resolving a single "unmappable character for encoding UTF-8" while retaining the entire project's encoding (including offending file) in UTF-8:

  1. Find the unmappable character's "\u" notation.
  2. Define it as a "const char":
   public static final char NBSP_CHAR = '\u00A0';
  1. Embed it in the original string. e.g.
  "first half"+NBSP_CHAR+"second half"

Not the answer you're looking for? Browse other questions tagged or ask your own question.