I'm trying to compile an android translator app from GitHub (Link of the App) which is about 4 years old project. I have upgraded its dependencies to androidx API 29 also dependent modules i.e. OpenCV, configured OpenCV 3.4.3. For all modules, I have set minSdkVersion to 14 or above and compile & target SDK version is now 29. Everything seems to work But its showing error for character encoding.
As its translator app, it converts characters of different languages to ASCII. For that, it has a class named Asciify.java (Asciify.java file link). The character set of this file, as well as other files, is UTF-8. But the Android Studio gives an error
error: unmappable character for encoding Cp1252
I search over the internet and read some articles/answers that suggested to change the encoding to compatible encoding. I tried to change the character set to windows-1252, US-ASCII but Android Studio shows Incompatible Encoding as
File 'Asciify.java' most likely isn't stored in the 'US-ASCII' encoding.
Why: BY_BYTES
Current encoding: 'UTF-8'
And the same is for windows-1252. I even tried to load these character sets forcefully But the android studio does nothing. Instead of reloading If I try to convert from one character set to another it corrupts the file. So my question is how can I fix this encoding error?
Thanks in advance.
Related
IntelliJ IDEA incorrect encoding in console output
https://www.jetbrains.com/help/idea/encoding.html
Turkish characters are not supported in intellij idea's terminal after run command.
I tried the above two links but I couldn't solve the problem.
console output photo-screenshot
Here is a related issue on YouTrack:
https://youtrack.jetbrains.com/issue/IDEA-291006/Running-the-Java-project-by-using-the-JDK-18-prints-the-garbled-
Feel free to watch it in order to be notified once it has updates. See this article if you are not familiar with YouTrack.
For turkish character support, you chould choose the international global UTF-8 format.
In IntelliJIdea
**File / Settings / Editor / File Encoding** / *.properties
Choose -> **Default encoding for properties files UTF-8
By the use of BOM configurations you can find the correct solution for your files. Do not forget that some choices of BOM for some class files can cause various \uxxxx errors like '\ufeff' error
Moreover you could choose also Global Encoding and Project encoding values just given above in the same tab as UTF-8 to get a more general solution for the future projects.
Screenshot of the web content created by the use of many components bfrom messages.properties
printed text or response from local server with turkish characters
Settings Page
I have a Java project and I'm using Apache Maven. All this time I was using Maven Java compiler plugin with parameters source=1.5 and target=1.5 defined in pom.xml file. Since I changed it to source=1.6 and target=1.6 I'm getting the following error:
XXXXXXXX.java:[54,27] unmappable character for encoding UTF-8
I've been testing different configurations and I turned showWarnings to value true so I could see that with value 1.5 for source and target this is a warning and not an error.
I need to change the Java compiler configuration anyway. Does anybody know why is this so and how can I solve this problem without editing all Java source files (there are hundreds of files with this issue now)?
My question is: why is this an error with source=1.6 and target=1.6
and it's a warning with source=1.5 and target=1.5?
Short anwser, because they said so:
-source 1.6 This is the default value. No language changes were
introduced in Java SE 6. However, encoding errors in source files are
now reported as errors, instead of warnings, as previously.
#DaveG concerns are valid, and you should try to:
Change the file encoding of your source files
find/replace those chars with your IDE
I have added some Hindi characters in Unicode to a Java program. Eclipse has no trouble with it, and can run this code, but Gradle keeps crashing - apparently this is due to javac making assumptions about character sets.
I believe I could handle this by converting my whole source directory to Unicode, and specifying encoding as "unicode" in the build.gradle file.
a) is there an official converter, and b) if so, how can I drive it from the build.gradle file?
The program in question is at https://github.com/jpaulm/drawfbp/blob/master/src/main/java/com/jpaulmorrison/graphics/MyFontChooser.java - line 272. Strangely, Gradle has no trouble with the Chinese characters at line 286, so why does only Hindi have problems? Help would be much appreciated!
This is embarrassing! I had one segment in Russian and another in Hindi (Devanagari), the former in ASCII, the latter in Unicode. I assumed my problem was with the Hindi, but it was actually with the Russian! When I converted the Russian to Unicode, everything worked fine (both Eclipse and Gradle)! Abject apologies! I guess we can close this one!
I don't know if this is a Java problem or Android's one. But recently I have updated everything concerning my Android development setup.
So I upgraded
Java to 1.7_40 64 bit (i have 1.7_25 32 bit also installed),
Android studio to 0.2.10,
SDK tools to version 22.2.1,
SDK platform tools to version 18.0.1,
Gradle 1.7
And my android app started to behave very oddly. Before this update of my tools this line of code worked perfectly just like expected:
Category.getNew(1,"СЕНДВИЧАРА")
Now, on the other side of the get new function
public static Category getNew(int id, String name){
Category result = new Category();
result.setId(id);
result.setName(name);
return result;
}
for the name parameter I get this string СЕÐ�ДВИЧÐ�Ð Ð� which is not what I expected, I want my СЕНДВИЧАРА back, this string is passed along to the UI.
I can't let that cryptic string to be displayed on on the UI.
Please help.
Ok guys I found the solution by myself. And I'll post the answer here for future reference.
Apparently the cause of my problem was in Gradle. This is the first time I've been using it, by suggestion of Android Studio.
I have noticed that Gradle isn't very good in reporting problems during the building of the application, it displays them at random. At one moment while building the app I noticed this error:
Gradle: error: unmappable character for encoding Cp1252
This error looks like it was the cause of my problem. Quick google search and I bump into this article: Get rid of “unmappable character for encoding Cp1252″ once and for all which in summary says to add new Environment Variable named JAVA_TOOL_OPTIONS with value of -Dfile.encoding=UTF8 this way Java would always use UTF-8 as default encoding.
I have a Java project and I'm using Apache Maven. All this time I was using Maven Java compiler plugin with parameters source=1.5 and target=1.5 defined in pom.xml file. Since I changed it to source=1.6 and target=1.6 I'm getting the following error:
XXXXXXXX.java:[54,27] unmappable character for encoding UTF-8
I've been testing different configurations and I turned showWarnings to value true so I could see that with value 1.5 for source and target this is a warning and not an error.
I need to change the Java compiler configuration anyway. Does anybody know why is this so and how can I solve this problem without editing all Java source files (there are hundreds of files with this issue now)?
My question is: why is this an error with source=1.6 and target=1.6
and it's a warning with source=1.5 and target=1.5?
Short anwser, because they said so:
-source 1.6 This is the default value. No language changes were
introduced in Java SE 6. However, encoding errors in source files are
now reported as errors, instead of warnings, as previously.
#DaveG concerns are valid, and you should try to:
Change the file encoding of your source files
find/replace those chars with your IDE