我在android中运行java代码,在运行此代码时使用oauth 2.0在android中创建凭据我遇到了问题:
这是我的问题:
引起:java.lang.ClassNotFoundException:在路径上找不到类“java.awt.Desktop”:DexPathList [[zip file“/data/app/com.retrofitdemo-1/base.apk”], nativeLibraryDirectories = [/ vendor / lib64,/ system / lib64]]
这是我的代码:
private static final GoogleClientSecrets googleSecrets = new GoogleClientSecrets();
googleSecrets.setInstalled(
new GoogleClientSecrets.Details()
.setClientId("542678605378-hlspiumlr34nq04cmjtkft17i6k3hvr0.apps.googleusercontent.com")
.setClientSecret("{client_secretid}")
);
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), googleSecrets, Arrays.asList(SCOPES))
.setAccessType("offline")
.build();
Credential credential1 = new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
Log.i("AA","credential1--"+credential1);
new MakeRequestTask(credential).execute();
如何在android中导入awt包?
答案 0 :(得分:0)
请帮助我,如何在android中导入awt包
你做不到。据推测,您正在使用一些专为桌面Java而非Android设计的库。找一些专为Android设计的替代库。
答案 1 :(得分:0)
尚未允许发表评论,因此这不是答案,但是也许有人可以将其添加为评论...
这是请求的堆栈跟踪示例。可以看出,这是oauth的Google代码:
f
以及试图与Desktop类对话的代码:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Desktop;
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.browse(AuthorizationCodeInstalledApp.java:129)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.onAuthorization(AuthorizationCodeInstalledApp.java:113)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:81)