0x01 现象

gradle.properties中定义了全局变量,然后从 build.gradle 中设置 app_name:

resValue "string", "app_name", "\"" +  project.app_name + "\""

gradle 生成的 xml 文件出现了中文乱码

<?xml version="1.0" encoding="utf-8"?>
<resources> <!-- Automatically generated file. DO NOT MODIFY --> <!-- Value from default config. -->
<string name="app_name" translatable="false">"测试应用"</string> </resources>

0x02 查错

检查了 gradle.properties 和 build.gradle ,确定编码是 UTF-8,也确认了 AndroidStudio 的编码是中文。

最后通过 google 解决了问题,stackoverflow 中提到的 documentation of java.util.Properties 中有写到

The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes as defined in section 3.3 of The Java Language Specification; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.


0x03 解决

确定了问题,解决就简单了,直接修改 gradle :

resValue "string", "app_name", "\"" + new String(project.APP_NAME.getBytes("iso8859-1"), "UTF-8") + "\""

gradle 生成的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<resources> <!-- Automatically generated file. DO NOT MODIFY --> <!-- Value from default config. -->
<string name="app_name" translatable="false">"测试应用"</string> </resources>

AndroidStudio 中 gradle.properties 的中文值获取乱码问题的更多相关文章

  1. androidStudio 中 gradle 常用功能

    1. gradle 使用 svn 当前版本信息. def getSvnRevision() { new ByteArrayOutputStream().withStream { os -> de ...

  2. 页面中的checkbox多选值获取

    依据name名称获取选中值 var arr=document.getElementsByName("name");arr是一个数组,就是所有checkbox的值:for(i=0;i ...

  3. 【转】IDEA 中配置文件properties文件中文乱码解决

    1.首先我们的IDEA文件编码一般都修改为utf-8(setting-->file encodings--->Global Encoding 和 Project Encoding 都设置为 ...

  4. AndroidStudio中gradle异常:unexpected end of block data

    原因:可能是Android buildTools版本不够高. 解决方法:打开build.gradle,将android中buildToolsVersion改为'20.0.0' (我使用的是gradle ...

  5. IDEA 中 显示 *.properties 为中文

      效果:  

  6. IE浏览器从页面向后台Controller传中文值出现乱码问题

    地址前面添加encodeURI() 1. var url = encodeURI('xxxAction.action?para='+中文); $('#cc').combobox({ url : url ...

  7. Eclipse导入的工程后referenced libraries中的jar包中文注释显示乱码解决方法

    Preferences-General-Workspace-Text file encoding 设置为uft-8 最后重启一下eclipse.

  8. 配置gradle.properties

    在一些项目中会分拆app 和 lib , 这时候引用support的时候,一旦更改版本会出现需要同步更改两个地方的问题.这种情况,可以通过配置gradle.properties实现替换. 在项目编译过 ...

  9. salesforce零基础学习(八十七)Apex 中Picklist类型通过Control 字段值获取Dependent List 值

    注:本篇解决方案内容实现转自:http://mysalesforceescapade.blogspot.com/2015/03/getting-dependent-picklist-values-fr ...

随机推荐

  1. zoj2112 Dynamic Rankings (主席树 || 树套树)

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  2. Codeforces Round #680 (Div. 2, based on Moscow Team Olympiad) D. Divide and Sum (思维,数学,逆元)

    题意:有一个长度为\(2n\)数组,从中选分别选\(n\)个元素出来组成两个序列\(p\)和\(q\),(\(p\)和\(q\)中只要有任意一个元素在\(a\)的原位置不同,就算一个新的情况),选完后 ...

  3. Balanced Numbers SPOJ - BALNUM

    代码+注释 1 //我感觉这道题最扯的就是我因为输入而TLE了半天,懵逼死了,想破脑袋也没想到因为输入TLE了半天 2 //题意:求区间内数字满足"奇数各数出现偶数次,偶数各数出现奇数次&q ...

  4. css整理之-----------选择器

    背景 在20年初时总感觉自己的css 不够用,想把css 相关的东西整理下,去年一整年都比较忙,忙着就到2021了,今天趁着有点时间,先从选择器开始吧. 听说图片可以提升颜值.... 选择器 CSS选 ...

  5. Java中的Lambda匿名函数后续

    函数式编程(函数式接口):一个接口只包含一个方法实现 public interface Lambda{ void method(); } // 调用 Lambda lambda = new Lambd ...

  6. MongoDB Up and Going

    # MongoDB Up and Going https://ide.c9.io/xgqfrms/mongodb # MongoDB 教程 https://www.runoob.com/mongodb ...

  7. ES6 ...rest In Action

    ES6 ...rest In Action const arr = [ 2.48, 13.77, 8.64, 20.17, 8.94, 8.07, 12.05, 5.71, 17.54, 2.63 ] ...

  8. Redis 大 key 问题 & 问题分析 & 解决方案

    Redis 大 key 问题 & 问题分析 & 解决方案 Redis 什么是 Redis 大 key 单个key 存储的 value 很大 hash, set,zset,list 结构 ...

  9. Emmet & VSCode

    Emmet & VSCode Emmet - the essential toolkit for web-developers https://emmet.io/ https://emmet. ...

  10. Proxifier

    Proxifier 使用教程 https://www.proxifier.com/ Proxifier允许不支持通过代理服务器工作的网络应用程序通过SOCKS或HTTPS代理和链进行操作. confi ...