16

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 ?

Mehdiway
  • 10,337
  • 8
  • 36
  • 68
  • 3
    Possible duplicate of [Android Studio : unmappable character for encoding UTF-8](http://stackoverflow.com/questions/23677855/android-studio-unmappable-character-for-encoding-utf-8) – TooCool Nov 27 '15 at 11:11

3 Answers3

53

Adding the following to build.gradle solves the problem :

android {
    ...
    compileOptions.encoding = 'ISO-8859-1'
Mehdiway
  • 10,337
  • 8
  • 36
  • 68
4

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.
Joybar
  • 41
  • 2
  • 1
    @xikitidistant http://superuser.com/questions/69091/batch-change-encoding-ascii-files-from-utf-8-to-iso-8859-1 – Dr.jacky Dec 13 '15 at 06:40
1

For Android Studio 2.2 you have To add compile option in gradle file of your project:

android { ... compileOptions { encoding "ISO-8859-1" sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } }

taranjeetsapra
  • 524
  • 7
  • 19