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. Educational Codeforces Round 83 D. Count the Arrays(组合,逆元,快速幂)

    题意: 从 m 个数中选 n - 1 个数组成先增后减的长为 n 的数组. 思路: 因为 n 个数中有两个数相同,所以每种情况实际上只有 n - 1 个不同的数--$c_m^{n - 1}$, 除去最 ...

  2. Educational Codeforces Round 85 (Rated for Div. 2)

    \(Educational\ Codeforces\ Round\ 85\ (Rated\ for\ Div.2)\) \(A. Level Statistics\) 每天都可能会有人玩游戏,同时一部 ...

  3. P1251 餐巾计划 (网络流)

    题意:餐厅每天会需要用Ri块新的餐巾 用完后也会产生Ri块旧的餐巾 每天购买新的餐巾单价p元 每天产出的旧餐巾可以送到快洗部花费每张c1元 在i + v1天可以使用 也可以花费c2元每张送到慢洗部 在 ...

  4. CodeForces 893C (并查集板子题)

    刷题刷到自闭,写个博客放松一下 题意:n个人,m对朋友,每寻找一个人传播消息需要花费相应的价钱,朋友之间传播消息不需要花钱,问最小的花费 把是朋友的归到一起,求朋友中花钱最少的,将所有最少的加起来. ...

  5. hdu4028 The time of a day (map+dp)

    Problem Description There are no days and nights on byte island, so the residents here can hardly de ...

  6. hdu4217 Data Structure?

    Problem Description Data structure is one of the basic skills for Computer Science students, which i ...

  7. POJ - 2553 tarjan算法+缩点

    题意: 给你n个点,和m条单向边,问你有多少点满足(G)={v∈V|∀w∈V:(v→w)⇒(w→v)}关系,并把这些点输出(要注意的是这个关系中是蕴含关系而不是且(&&)关系) 题解: ...

  8. 在Ubuntu虚拟机上搭建青岛OJ

    源码地址为:https://github.com/QingdaoU/OnlineJudge 可参考的文档为:https://github.com/QingdaoU/OnlineJudgeDeploy/ ...

  9. C#之抛异常

    using System; namespace Demo { class Program { static void Main(string[] args) { try { BLLLayer(); } ...

  10. 动态链接库(DLL)的创建和使用

    最近想做个记录日志的C++库,方便后续使用.想着使用动态库,正好没用过,学习下.概念这里不赘述.学习过程中碰到的几点,记录下来.学习是个渐进的过程,本文也是一个逐渐完善的过程. 一.Static Li ...