AndroidStudio 中 gradle.properties 的中文值获取乱码问题
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 的中文值获取乱码问题的更多相关文章
- androidStudio 中 gradle 常用功能
1. gradle 使用 svn 当前版本信息. def getSvnRevision() { new ByteArrayOutputStream().withStream { os -> de ...
- 页面中的checkbox多选值获取
依据name名称获取选中值 var arr=document.getElementsByName("name");arr是一个数组,就是所有checkbox的值:for(i=0;i ...
- 【转】IDEA 中配置文件properties文件中文乱码解决
1.首先我们的IDEA文件编码一般都修改为utf-8(setting-->file encodings--->Global Encoding 和 Project Encoding 都设置为 ...
- AndroidStudio中gradle异常:unexpected end of block data
原因:可能是Android buildTools版本不够高. 解决方法:打开build.gradle,将android中buildToolsVersion改为'20.0.0' (我使用的是gradle ...
- IDEA 中 显示 *.properties 为中文
效果:
- IE浏览器从页面向后台Controller传中文值出现乱码问题
地址前面添加encodeURI() 1. var url = encodeURI('xxxAction.action?para='+中文); $('#cc').combobox({ url : url ...
- Eclipse导入的工程后referenced libraries中的jar包中文注释显示乱码解决方法
Preferences-General-Workspace-Text file encoding 设置为uft-8 最后重启一下eclipse.
- 配置gradle.properties
在一些项目中会分拆app 和 lib , 这时候引用support的时候,一旦更改版本会出现需要同步更改两个地方的问题.这种情况,可以通过配置gradle.properties实现替换. 在项目编译过 ...
- salesforce零基础学习(八十七)Apex 中Picklist类型通过Control 字段值获取Dependent List 值
注:本篇解决方案内容实现转自:http://mysalesforceescapade.blogspot.com/2015/03/getting-dependent-picklist-values-fr ...
随机推荐
- 2020牛客暑期多校训练营 (第二场) All with Pairs
传送门:All with Pairs 题意:给你n个字符串,求出,f(si,sj)的意思是字符串 si 的前缀和字符串 sj 后缀最长相等部分. 题解:先对所有的字符串后缀hash,用map记录每个h ...
- Codeforces Round #682 (Div. 2) B. Valerii Against Everyone (思维)
题意:给你一组数\(b\),对于每个\(b_i\),相对应的\(a_i=2^{b_i}\),问你是否能找出两个不相交的区间,使得两个区间的\(a_i\)的元素和相等. 题解:对于任意一个\(2^k\) ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)
题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...
- tkinter 实现爬虫的UI界面
使用python的内置模块tkinter编写了爬取51Ape网站(无损音乐的百度云链接)的UI界面 tkinter入门简单, 但同时在编写的过程中因为文档的缺少很不方便. 下面是UI界面模块的编写,由 ...
- Dapr微服务应用开发系列2:Hello World与SDK初接触
题记:上篇介绍了Dapr的环境配置,这次我们来动手尝试一下Dapr应用的开发 Hello World Dapr应用的Hello World其实和其他的Hello World一样简单: 首先用你喜欢的语 ...
- 【转】K8S中部署Helm
K8S中的包管理工具 1. 客户端Helm(即Helm) 通过脚本安装:curl https://raw.githubusercontent.com/helm/helm/master/scripts ...
- LINUX - 寄存器和堆栈
堆栈模型: 函数调用: EBP:ESP EBP当前调用函数的栈底: ESP当前调用函数的栈顶: ---------------------------------------------------- ...
- npm ci All In One
npm ci All In One npm 性能优化 npm ci 使用干净的面板安装项目 https://docs.npmjs.com/cli/v6/commands/npm-ci # npm cl ...
- Promise thenable All In One
Promise thenable All In One Promise thenable 是指一个函数或一个对象的里面定义了一个 then 方法 Promises/A+ https://promise ...
- 使用 js 实现一个简易版的模版引擎
使用 js 实现一个简易版的模版引擎 regex (function test() { this.str = str; })( window.Test = ...; format() { let ar ...