gpt4 book ai didi

android - Google API : java. lang.ClassNotFoundException:找不到类 "sun.misc.Service"

转载 作者:行者123 更新时间:2023-12-05 00:17:48 28 4
gpt4 key购买 nike

我已经导入了所有必要的谷歌依赖项来验证用户:

def play_services_version = "15.0.1"
implementation 'com.google.api-client:google-api-client:1.33.0'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.32.1'
implementation 'com.google.apis:google-api-services-drive:v3-rev20211107-1.32.1'
implementation 'com.sun.net.httpserver:http:20070405'
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation "com.google.android.gms:play-services-auth:$play_services_version"
implementation "com.google.android.gms:play-services-drive:$play_services_version"
implementation 'com.squareup.okio:okio:1.14.0'
接收用户凭证。
/**
* Creates an authorized Credential object.
* @param HTTP_TRANSPORT The network HTTP Transport.
* @return An authorized Credential object.
* @throws IOException If the credentials.json file cannot be found.
*/
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
// Load client secrets.
InputStream in = DriveQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));


//Token Folder
java.io.File s = new File(TOKENS_DIRECTORY_PATH);
if(!s.exists()){
boolean mkdir = s.mkdir();
}
File tokenFolder = new File(con.getFilesDir() +
File.separator + TOKENS_DIRECTORY_PATH);
if (!tokenFolder.exists()) {
tokenFolder.mkdirs();
}

// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(tokenFolder))
.setAccessType("offline")
.build();

LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();

Credential credential = new AuthorizationCodeInstalledApp(flow,receiver ).authorize("user");
//returns an authorized Credential object.
return credential;
}
因为那是 official google 文档,代码应该是最新版本,但是执行代码,我收到 Failed resolution of: Lsun/misc/Service Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service" 错误。
这是由于缺少依赖项还是谷歌的错误?

最佳答案

the documentation that you linked to的第一句话|是:“完成本页其余部分中描述的步骤,以创建一个简单的 Java 命令行应用程序,该应用程序向 Drive API 发出请求。” (强调)这些说明不适用于 Android。

关于android - Google API : java. lang.ClassNotFoundException:找不到类 "sun.misc.Service",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71788616/

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