Android Studio : unmappable character for encoding UTF-8
Asked Answered
K

10

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

Kingpin answered 15/5, 2014 at 12:11 Comment(0)
S
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

Stadler answered 4/7, 2014 at 7:30 Comment(5)
Thank you sir. I was having up to 100 errors when building due to spanish javadoc.Smyth
~"left lower corner of IDE". What do you mean? Do you have a screenshot of that button?Justly
@Justly please click on the link in my answer. There are many interesting screenshots.Stadler
"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.Derivation
Remember to change your encoding in both build.gradle and your file.Prepare
V
13

Adding the following to build.gradle solves the problem :

android {
 ...
compileOptions.encoding = 'ISO-8859-1'
 }
Vair answered 10/10, 2015 at 4:45 Comment(0)
P
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

Provenience answered 26/8, 2015 at 12:13 Comment(0)
F
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

Fra answered 17/12, 2014 at 12:18 Comment(0)
C
2

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

I did it only way to fix this error.

Chicle answered 8/8, 2016 at 6:58 Comment(0)
S
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.
Sexagesimal answered 24/2, 2019 at 15:12 Comment(0)
F
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 !

Fenn answered 20/1, 2016 at 4:36 Comment(0)
T
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.

Tarlatan answered 28/7, 2020 at 0:43 Comment(0)
M
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.

Matzo answered 4/11, 2020 at 12:30 Comment(0)
L
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"
Lodging answered 25/7, 2023 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.