Android studio doesn't recognize UTF-8 encoding - android

The problem is that when I use UTF-8 characters like ā, ē, š Android Studio translates them to some different symbols.
This is Log.d() that I'm passing:
Log.d("Test", "ššāā");
The result that I get is
D/Test: ЕЎЕЎДЃДЃ
And that is not only for Logcat. It passes same thing everywhere I try to use these characters.

Check your gradle file for any encodings like
compileOptions.encoding = 'windows-1251'

Can you try this:
File -> Other Settings -> Default Settings, then search for "File Encodings", change Project Encoding to UTF-8

Make sure all the below are set to UTF-8:
Global Encoding (Settings > Editor > File Encodings)
Project Encoding (Settings > Editor > File Encodings)
Default encoding for properties files (Settings > Editor > File Encodings)
The actual file encoding at the bottom right in Android Studio

Related

Android Studio 3.2.1, XML bad indent format

After updating to Android Studio 3.2.1 the XML files format is very annoying and bad, how can we fix it? Can we change it from somewhere in settings to previews type?
On Android Studio 3, Go to :
Preferences > Editor > Code style > XML then on Scheme switch to Default instead of Project.
You can then use those shortcuts to indent your code:
Windows:
Ctrl + Alt + L
macOS:
Option + Command + L
You can edit your code styles under File > Settings > Editor > Code Style > XML
If you want to preview a specific file, just paste that file's contents into the preview window.
Open File > Settings > Editor > Code Style > XML
Now in layout file make sure you have selected wrap attributes as Wrap always.
Screenshot

how to change terminal font size on Android Studio?

I want to change the Terminal font size. But I have no idea to do it.
Who can solve it?
in window : File - > Settings - > Editor - > Color scheme -> Console Font
File > Settings (Ctrl + Alt + S) > Editor > Color Scheme > Console Font
Thanks for everyone, I have solve it. I also do this steps some days ago, but it is not effective immediately. I try to do it once again just now and then restart AndroidStudio , Everything is OK. Thanks!
In Android Studio 3.0 File > Settings > Editor > Color & Fonts > Console Font....then click Apply and Ok
If you are android studio version above 3.0 :
File > Settings > Editor(expand it) > Color scheme(Expand it) > Console Font > Tick checkbox of Use console font instead of default > Enter size of font you want use > click Apply > Click Ok

Referencing a japanese/chinese string in gradle.properties from strings.xml results in an unknown behaviour

I'm referencing a gradle variable from a string.xml the following way:
gradle.properties
APP_NAME_JAPANESE="日本語"
build.gradle
resValue 'string', 'APP_NAME_JAPANESE', APP_NAME_JAPANESE
strings.xml
<string name="app_name">#string/APP_NAME_JAPANESE</string>
The generated file generated.xml have the following string
<string name="APP_NAME_JA" translatable="false">"ã¢ãã¿ã¼ãã«ã¹"</string>
As we can see charaters are unreadables.
All files are UTF-8 encoded.
If instead of putting the variable in the gradle.properties I put it directly on build.gradle resValue 'string', 'APP_NAME_JAPANESE', "日本語", everything is working properly.
Could this be a bug in the gradle system?
Java properties files by definition are not UTF-8 encoded, unless you explicitly parse them as UTF-8 files.
They are by default ISO-8859-1 encoded with unicode escapes for characters out of that range.
Fix your properties file and everything will work like a charm.
As you are using android I guess you are using Android Studio which is just a specialized IntelliJ IDEA. There you can change in the settings the encoding for properties files to ISO-8859-1 with transparent native-to-ascii escaping. This allows you to see the UTF-8 glyphs in the editor, but the file will be saved automatically with the unicode escapes as necessary. Alternatively you can use the native2ascii tool on the UTF-8 encoded properties file to do that transformation before you start your actual build. But I really recommend using the proper encoding that most tools that can deal with property files are expecting.
I've tried changing the encoding but, still the same issue is happening.
Finally I decided to set the strings in base64 format and then decode the strings in the build.gradle like this
resValue 'string', 'APP_NAME_JA', new String(APP_NAME_JA.decodeBase64(), "UTF-8")

How to let build.gradle support multi-language?

I have a question, I write script "resValue("string", "app_name", "Test")" in the build.gradle file and it occured an error that I have already anounce the same value in the "string.xml" file as "Test".
Here is the question, how to make gradle file support Chinese and English ?
Thank you !
You need to use an encoding like UTF-8 while building the gradle by setting -
-encoding UTF-8 -docencoding utf-8 -charset utf-8
Or something like this -
android {
...
compileOptions.encoding = 'ISO-8859-1'
}
Or through the settings -
File -> Settings -> Editor -> File encodings -> set UTF-8 for
IDE Encoding
Project Encoding
Default encoding propertie file
Press OK
Rebuild Project
Build -> Rebuild project

Issue Displaying Japanese Characters in Eclipse

My ecliplse IDE is displaying junk characters instead of the correct japanese characters...
Tried many strategies , my encoding is set to UTF-8...but still no outcome.
Screenshots for references are attached..
Any help will be accepted...
Thanks in advance.
Open this file in your Workspace directory: <your_workspace_dir>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.ide.prefs
Append this line to that file: IDE_ENCODINGS_PREFERENCE=EUC-JP'Shift_JIS'
Restart Eclipse
Open Setting: Window > Preferences > General > Workspace > Text File
Encoding. In Other: select "EUC-JP" in dropdown.
Ok -> re-open that file;
The xml file might be saved as SJIS(MS932).
Maybe this page can help you:
http://internetmarketingcoding.com/how-to-convert-japanese-shift-jis-text-to-utf-8
Open the eclipse.ini config file in the eclipse home folder
Add the new parameter -Dfile.encoding=SJIS
Close and Open the eclipse.

Categories

Resources