Jonelix
Jonelix

Reputation: 1

java.lang.IllegalStateException error when I am using a more updated version of the needed library

I am trying to call the methods to modify Google Keep in my Android application project. Right now I just want to make the builder work that can handle the tasks.

Dependencies:

implementation("com.google.firebase:firebase-auth:22.3.1")
implementation("com.google.android.gms:play-services-auth:21.1.0")
implementation ("com.google.api-client:google-api-client:2.4.0")
implementation ("com.google.apis:google-api-services-keep:v1-rev20210528-1.31.0")

Code I want to fix:

public class KeepQuickstart {

    public static void createNewNote(Context context){
        GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
        if (account != null) {

            String idToken = account.getIdToken();
            GoogleCredentials credentials = GoogleCredentials.create(new AccessToken(idToken, null));
            HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
            try{
            Keep keepService = new Keep.Builder(new NetHttpTransport(), GsonFactory.getDefaultInstance(), requestInitializer)
            .setApplicationName("Ecco6").build();
                // Create note content
                Section noteBody = new Section().setText(new TextContent().setText("Finish preparations by tomorrow!"));
                Note newNote = new Note().setTitle("Customer call next week").setBody(noteBody);
                // Create the note
                try {
                    keepService.notes().create(newNote).execute();
                    // Handle success, e.g., show a toast message
                } catch (Exception e) {
                    // Handle creation failure
                    e.printStackTrace();
                }

            }catch (ExceptionInInitializerError e){
                System.out.println(e.getCause().toString());
            }

        } else {
            // User is not signed in, handle this case
            System.out.println("User not logged in.");
        }
    }
}

I have really struggled to find the way to use the API in my Android application but I feel like I am getting close. But now I have arrived at an error I don't know how to fix. When I call the createNewNote method I get the error:

java.lang.IllegalStateException: You are currently running with version 2.4.0 of google-api-client. You need at least version 1.31.1 of google-api-client to run version 1.31.0 of the Google Keep API library.

Any help is greatly appreciated!!

I have tried different ways to pass the HttpRequestInitializer so the token is correct and I can get access to the user's notes, but nothing has worked so far and I am stuped by the current error message.

Upvotes: 0

Views: 168

Answers (1)

qtxo
qtxo

Reputation: 1573

Use the most updated lib version for :

implementation ("com.google.apis:google-api-services-keep:v1-rev20220322-2.0.0")

Upvotes: 0

Related Questions