简体   繁体   English

谷歌 API: java.lang.ClassNotFoundException: 没有找到 class "sun.misc.Service"

[英]Google API: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service"

I've imported all necessary google dependencies for authenticate the user:我已经导入了所有必要的谷歌依赖项来验证用户:

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'

Receiving the user credetials.接收用户凭证。

/**
 * 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;
}

Since that Is official google documentation, the code should be on newest version, however executing the code, I receive Failed resolution of: Lsun/misc/Service Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service" error.由于那是谷歌官方文档,代码应该是最新版本,但是执行代码,我收到Failed resolution of: Lsun/misc/Service Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service"错误。

Is this due to missing dependencies or is that a bug from google?这是由于缺少依赖项还是谷歌的错误?

The first sentence of the documentation that you linked to is: "Complete the steps described in the rest of this page to create a simple Java command-line application that makes requests to the Drive API."您链接到的文档的第一句是:“完成此页面的 rest 中描述的步骤,以创建一个简单的 Java 命令行应用程序,该应用程序向驱动器 ZDB974238714CA8DE6DE634A7CE1D08 发出请求。” (emphasis added) Those instructions are not for Android. (已添加重点)这些说明不适用于 Android。

Sun HTTP server packages are not included in Android SDK so you can't run those there. Sun HTTP 服务器软件包未包含在 Android SDK 中,因此您无法在其中运行它们。

But you can include the libraries by yourself.但是您可以自己包含这些库。

Just download the 2 jars (http-2.2.1 and sun-common-server) provided in this medium post .只需下载此中帖子中提供的 2 jars(http-2.2.1 和 sun-common-server)即可。 Add them to your app/libs folder in Android project and include the following in your build.gradle:将它们添加到 Android 项目中的 app/libs 文件夹中,并在 build.gradle 中包含以下内容:

implementation fileTree(dir: 'libs', include: ['*.jar'])

Hopefully this gets you up and running希望这能让你启动并运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassNotFoundException:在路径上找不到 class“com.sun.mail.util.MailLogger”: - java.lang.ClassNotFoundException: Didn't find class "com.sun.mail.util.MailLogger" on path: java.lang.ClassNotFoundException:找不到带有newrelic的类*。*。MainActivity - java.lang.ClassNotFoundException: Didn't find class *.*.MainActivity with newrelic java.lang.ClassNotFoundException:在路径:DexPathList上找不到类… - java.lang.ClassNotFoundException: Didn't find class … on path: DexPathList java.lang.ClassNotFoundException:找不到类 - java.lang.ClassNotFoundException: Didn't find class Java.lang.ClassNotFoundException:没有找到类Kotlin - Java.lang.ClassNotFoundException: Didn't find class Kotlin React Native java.lang.ClassNotFoundException:找不到类 - React Native java.lang.ClassNotFoundException: Didn't find class Android java.lang.ClassNotFoundException: 未找到 class - Android java.lang.ClassNotFoundException: Didn't find class java.lang.ClassNotFoundException:在路径:DexPathList上找不到类… - java.lang.ClassNotFoundException: Didn't find class … on path: DexPathList java.lang.ClassNotFoundException:在路径上找不到 class:dexpathlist - java.lang.ClassNotFoundException: Didn't find class on path: dexpathlist 原因:java.lang.ClassNotFoundException:在路径上找不到类 - Caused by: java.lang.ClassNotFoundException: Didn't find class on path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM