Android使用commons-codec-1.6 遇到的问题
2013-09-25 16:42
295 查看
由于需要用到Android 中的md5加密,之前在服务端使用该jar觉得很赞,于是导入android工程也使用,出现问题了,
找不到encodeHexString()方法,
后来在万能的stackoverflow 找到解决方案:
Replace this statement with the following and it will work:
Similarly, for shaHex exampl, you can change it to
This works because even though Android does not have encodeHexString(), it does have encodeHex(). Hope this would help others who run into the same issue.
根本原因应该是android内部库也有一个org.apache.commons.codecs.*的 jar,导致包名冲突,而优先加载了系统的,而系统的jar包中却没有encodeHexString():
解决方案:
方案1
以上的解决方法,做encodeHexString的工作吧,encodeHexString没有,encodeHex还是有的。
方案2.源码重新编译,改下报名为org.myapache.commons.codecs,这下不冲突了,哈哈。
找不到encodeHexString()方法,
后来在万能的stackoverflow 找到解决方案:
String s = DigestUtils.md5Hex(data);
Replace this statement with the following and it will work:
String s = new String(Hex.encodeHex(DigestUtils.md5(data)));
Similarly, for shaHex exampl, you can change it to
String hash = new String(Hex.encodeHex(DigestUtils.sha("textToHash");
This works because even though Android does not have encodeHexString(), it does have encodeHex(). Hope this would help others who run into the same issue.
根本原因应该是android内部库也有一个org.apache.commons.codecs.*的 jar,导致包名冲突,而优先加载了系统的,而系统的jar包中却没有encodeHexString():
解决方案:
方案1
以上的解决方法,做encodeHexString的工作吧,encodeHexString没有,encodeHex还是有的。
方案2.源码重新编译,改下报名为org.myapache.commons.codecs,这下不冲突了,哈哈。
相关文章推荐
- Android中如果你也使用commons-codec-1.6并且出现了问题
- Android使用commons-codec-1.6进行数据加密的过程中出现的异常
- # android studio使用遇到的问题
- Android项目使用support v7时遇到的各种问题
- 使用jetbrains idea开发android遇到的第一个问题
- android学习-----使用TabLayout实现Tab选项卡以及遇到的一些问题(二)
- 拿什么拯救:Android Studio 时代 继续使用Eclipse开发Android app时遇到的几个问题以及解决办法
- Android项目使用support v7时遇到的问题
- android 在使用studio 编写百度地图中遇到APP Scode码校验失败 问题
- Android项目使用support v7时遇到的各种问题(转载百度经验)
- Android项目使用support v7时遇到的各种问题
- Android使用DOM来编辑XML时遇到的问题——无法保存
- android 定时器 Timer 使用 及其遇到的问题
- 使用checkinstall1.6.1时遇到的问题
- 解决android使用gson解析json字符串,并使用混淆编译方式打包apk遇到的问题
- 在android上使用opencv的ocl模块遇到的问题(一)
- Android使用Ant打包所遇到问题的解决方法
- Sharesdk 使用中遇到的问题 Android
- Android下使用DatagramPacket进行局域网通信遇到的问题和分析
- 关于android Listview 使用时遇到的几个问题