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

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个谷歌文档,所以代码应该是最新版本的,但是执行代码时,我收到了Failed resolution of: Lsun/misc/Service Caused by: java.lang.ClassNotFoundException: Didn't find class "sun.misc.Service" 0个错误.

这是因为缺少依赖关系,还是谷歌的错误?

推荐答案

the documentation that you linked to的第一句话是:"完成本页其余部分描述的步骤,创建一个简单的Java命令行应用程序,向驱动API发出请求."(重点补充)这些说明不适用于Android.

Android相关问答推荐

如何将结果从viewModelScope传递到活动

Android Jetpack Compose Material3主题配色方案

替换- prop -中的值(adb shell getprop)

泛型类型lambda函数参数作为函数参数

无法在Android中创建通知频道

Android和Rust,OpenSSL交叉编译在ARM V7上链接失败

我到底应该如何分享我的应用程序中的图片?

这款应用与最新版本的Android不兼容.在Android 14中

在Jetpack Compose中,如何判断屏幕是否已重新组合?

如果我的圆形图像的顶部居中于卡片内部,我如何在其下方画一条弧线?

Android-交叉引用表中的ForeignKey用于什么?

Android v31 及更低版本中 ImageView 中的圆角

块不起作用,出现 "只有安全的 (?.)... " 错误

如何在 Jetpack Compose 中对齐按钮底部中心?

以下代码如何在 Android 上运行

在模块 jetified-kotlin-stdlib-1.8.10 中发现重复的类 kotlin.random.jdk8,带有启动基准

通过 adb 解压并重新安装后 Android 应用程序崩溃

Android CompanionDeviceManager 永远找不到任何附近的蓝牙设备

如何对齐文本和图标可组合,以便即使在文本溢出后它们也能保持在一起?

在jetpack compose中将图像添加到脚手架顶部栏