是否有同时兼容 Android 和 Java 的 Base64 库 [英] Is there a Base64 library that is compatible with both Android and Java

查看:28
本文介绍了是否有同时兼容 Android 和 Java 的 Base64 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于 Java 和 Android 项目的通用库,它需要一个 base64 编码器/解码器.问题是,Apache commons 库不适用于 Android,至少我无法成功实现 - 由于 Android 已经实现和早期版本,因此每当我尝试编码或解码时都会在运行时导致错误:

I have a common library that I use for both Java and Android projects and it requires a base64 encoder/decoder. The trouble is, the Apache commons library does not work with Android, at least not that I have been able to successfully implement - due to Android already implementing and earlier version and thus causing an error at run time whenever I attempt to encode or decode:

Base64.decodeBase64

返回错误:

AndroidRuntime(1420): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.decodeBase64

如果有人知道与 Java 和 Android 兼容的 base64 库,或者可以向我解释如何解决 Apache commons 问题,我将不胜感激.:^)

If anyone knows of a base64 library that is compatible with both Java and Android, or can explain to me how to get around the Apache commons issue, I would be very grateful. :^)

推荐答案

只有base64".它是如此微不足道,您可以搜索任何java base64"并使用任何实现.

There's just "base64". It so trivial that you can google for any "java base64" and use any implementation.

编辑

如果您以 API8 之前为目标,只需从 API8 中获取 Base64 实现的源代码(它是 android/util/Base64.java) 并复制到你的项目中.

If you target pre API8, simply grab the source from Base64 implementation from API8 (it is android/util/Base64.java) and copy into your project.

这篇关于是否有同时兼容 Android 和 Java 的 Base64 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆