4
votes

I am running java code in android for making credentials using oauth 2.0 in android when i run this code I'm getting issue:

This is my issue:

Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.Desktop" on path: DexPathList[[zip file "/data/app/com.retrofitdemo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]

This is my code:

 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();

How to import awt package in android?

2
I having this problem too, do you succeed to solve it? - Guy

2 Answers

1
votes

Please kindly help me,how to import awt package in android

You can't. Presumably, you are using some library that is designed for use with desktop Java, not Android. Find some replacement library that is designed for use with Android.

0
votes

Not allowed to comment yet so this is not answer, but perhaps someone can add it as a comment...

Here's the stack trace sample requested. As can be seen this is Google code for oauth:

    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)

And the code that's trying to talk to the Desktop class:

   /**
   * Open a browser at the given URL using {@link Desktop} if available, or alternatively output the
   * URL to {@link System#out} for command-line applications.
   *
   * @param url URL to browse
   */
  public static void browse(String url) {
    Preconditions.checkNotNull(url);
    // Ask user to open in their browser using copy-paste
    System.out.println("Please open the following address in your browser:");
    System.out.println("  " + url);
    // Attempt to open it in the browser
    try {
      if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Action.BROWSE)) {
          System.out.println("Attempting to open that address in the default browser now...");
          desktop.browse(URI.create(url));
        }
      }