gpt4 book ai didi

java.util.Base64 未找到,无法使用 android.util.Base64 因为类是 Android 外部使用的依赖项

转载 作者:行者123 更新时间:2023-12-02 09:25:08 24 4
gpt4 key购买 nike

我得到 Caused by: java.lang.ClassNotFoundException: Did not find class "java.util.Base64"on path: DexPathList in an android application,并且因为外部解码器类由 Android 和 android 之外的另一个 java 应用程序使用我不能像很多人建议的那样使用“andorid.util.Base64”。我们如何在android中解析java.util.Base64?

我找不到其他可以尝试的东西,我见过的唯一其他答案是使用 android 类。这不是一个选择。

这是解压缩 Base64 消息的共享方法,在 Android 和服务中都使用。

    byte[] bytes = Base64.getDecoder().decode(message.getMessage());
GZIPInputStream gzipStream = new GZIPInputStream(new ByteArrayInputStream(bytes));
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(gzipStream, StandardCharsets.UTF_8));
final StringBuilder messageString = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
messageString.append(line);
}
messageJson = messageString.toString();

最佳答案

我们通过使用 Android 和非 andorid 都可以使用的 Base64 编码/解码 apache 库解决了这个问题。

 <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.13</version>
</dependency>
<小时/>
org.apache.commons.codec.binary.Base64;

关于java.util.Base64 未找到,无法使用 android.util.Base64 因为类是 Android 外部使用的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58396552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com