由于需要用到Android 中的md5加密,之前在服务端使用该jar觉得很赞,于是导入android工程也使用,出现问题了,
找不到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,这下不冲突了,哈哈。