【发布时间】:2021-09-30 02:14:14
【问题描述】:
我构建了一个带有服务帐户的 Android 应用程序,用于将文件上传到 Google Drive,该应用程序在模拟器和 Android Nougat 上完美运行。现在,我在装有 Android 8.1 的三星 Galaxy Tab A 上进行了尝试,在实施服务帐户之前一切正常。现在,当我尝试从中将文件保存到 google Drive 上时,出现错误:
java.lang.NoSuchMethodError: No static method decodeBase64(Ljava/lang/String;)[B in class Lorg/apache/commons/codec/binary/Base64; or its super classes (declaration of 'org.apache.commons.codec.binary.Base64' appears in /system/framework/org.apache.http.legacy.boot.jar)
有问题的代码是我登录的地方,特别是在fromStream 方法中:
private Credential authorize () throws IOException {
InputStream in = getAssets().open("credentials.json");
return GoogleCredential.fromStream(in)
.createScoped(Collections.singleton(DriveScopes.DRIVE_FILE));
}
这些是实现的新库,我添加了 commons-codec:commons-codec:1.15 因为我读到它可能是由它引起的,但它仍然不起作用:
//API Google Drive
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation('com.google.api-client:google-api-client-android:1.26.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
// https://mvnrepository.com/artifact/com.google.apis/google-api-services-drive
implementation('com.google.apis:google-api-services-drive:v3-rev136-1.25.0') {
exclude group: 'org.apache.httpcomponents'
exclude module: 'guava-jdk5'
}
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
implementation 'commons-codec:commons-codec:1.15'
我该如何解决?
编辑:这些是我在整个项目中使用的唯一 apaches 库,但它们已用于在本地编写 .xlsx 文件,并且在实施服务之前从未在 Galaxt Tab A 上给我任何问题凭据:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
【问题讨论】:
-
阅读关于 Android 拥有自己的 Bas64 库的评论:stackoverflow.com/q/54879286/8016720
-
@JohnHanley 是的,这是我遵循的指南。我在有问题的类中实现了 'commons-codec:commons-codec:1.10' 和方法 decodeBase64 但没有任何改变。
-
你为什么不在 Android 上使用 Android 库?
-
@JohnHanley 我从未使用或声明过库 'org.apache.commons.codec.binary.Base64',我不知道他从哪里得到它
-
您的问题没有显示您的代码、导入等。这意味着我必须猜测。
标签: java android base64 codec google-drive-android-api