Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Characters charset from sub module wrong in Android studio

I have an android app in Android Studio which was imported from eclipse. Beside the android module the project contains java modules.

The java modules handle charsets wrong, the android module does correct. I have this method implemented in an Activity and also in an sub-module class:

public String getUmlaute() {
    return "öäüßÖÄÜ " + Charset.defaultCharset();
}

This

submoduleClass.getUmlaute() + "--" + getUmlaute();

returns

öäüßÖÄÜ java.nio.charset.CharsetICU[UTF-8] -- öäüßÖÄÜ java.nio.charset.CharsetICU[UTF-8]

All files are UTF-8 encoded of cause. Android Studio and also notepad++ confirm this and also the correctness of the letters.

Android Studio SettingsAndroid Studio Settings

I tried both, clear the subproject default encoding and set it to UTF-8. No difference.

Whats going wrong here? Is there an encoding option missing?

like image 229
Markus Kreth Avatar asked Nov 01 '25 08:11

Markus Kreth


1 Answers

Finally solved, but weired. I added

compileJava.options.encoding = 'UTF-8'

to every java build.gradle file.

I added

android {
    compileOptions.encoding = "UTF-8"

to the android build.gradle file.

In "Settings"->File Encodings I set the Default Encoding of the Java Modules to windows-1252.

That did the trick. The files are still utf-8

Maybe its a windows file system problem. This is NTFS by the way.

like image 66
Markus Kreth Avatar answered Nov 04 '25 07:11

Markus Kreth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!