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. oranges-给mini os 添加内存管理,进程多级反馈队列,进程内存完整性度量

    参考: 内存管理: https://www.jianshu.com/p/49cbaccd38c5 crc校验 https://www.cnblogs.com/zzdbullet/p/9580502.h ...

  2. vue watch All In One

    vue watch All In One var vm = new Vue({ data: { a: 1, b: 2, c: 3, d: 4, e: { f: { g: 5 } } }, watch: ...

  3. 通过改写 原始对象的paint 方法,来设置对象的border颜色

    解决方案: //通过改写 原始对象的paint 方法,来设置对象的border颜色 1. package test1;import java.awt.Color;import java.awt.Gra ...

  4. 如何通过 terminal 查看一个文件的 meta信息

    如何通过 terminal 查看一个文件的 meta 信息 Linux shell stat 查看文件 meta 信息 stat stat指令:文件/文件系统的详细信息显示: 使用格式:stat 文件 ...

  5. css break-inside

    css break-inside The break-inside CSS property sets how page, column, or region breaks should behave ...

  6. Deno 1.0 & Node.js

    Deno 1.0 & Node.js A secure runtime for JavaScript and TypeScript. https://deno.land/v1 https:// ...

  7. export excel

    export excel sheet.js https://sheetjs.com/ https://github.com/SheetJS/sheetjs excel.js https://www.n ...

  8. TypeScript 3.7 RC & Nullish Coalescing

    TypeScript 3.7 RC & Nullish Coalescing null, undefined default value https://devblogs.microsoft. ...

  9. svg & stroke & style & class

    svg & stroke & style & class svg selected style methods style class, !important fill, st ...

  10. BGV再度爆发,流通市值破500万美金!

    BGV似乎以超乎寻常的姿态,开启了爆发的模式.这两天,BGV一路上涨,日内最高涨至548.78美金,24小时成交额达到了98.07万美金,24小时成交量达到1844.93枚BGV,流通市值更是突破了5 ...