Human
Human

Reputation: 10815

Android Studio : unmappable character for encoding UTF-8

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

Upvotes: 64

Views: 118157

Answers (10)

Introspective
Introspective

Reputation: 736

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"

Upvotes: 0

Waldmann
Waldmann

Reputation: 1817

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.

Upvotes: 0

Shah Nizar Baloch
Shah Nizar Baloch

Reputation: 63

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.

Upvotes: 0

ibrahnerd7
ibrahnerd7

Reputation: 11

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.

Upvotes: 1

gc986
gc986

Reputation: 756

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

I did it only way to fix this error.

Upvotes: 2

Rahul
Rahul

Reputation: 874

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 !

Upvotes: 0

Priyanka Dadhich
Priyanka Dadhich

Reputation: 148

Adding the following to build.gradle solves the problem :

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

Upvotes: 13

Samy Parjou
Samy Parjou

Reputation: 121

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

Upvotes: 12

mrblrrd
mrblrrd

Reputation: 1529

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

Upvotes: 136

anil
anil

Reputation: 2113

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

Upvotes: 5

Related Questions