Is there a Base64 library that is compatible with both Android and Java(是否有同时兼容 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 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有同时兼容 Android 和 Java 的 Base64 库


基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01