Compatibility problems when using 2.0.0 google-api-client for Gmail calls

Viewed 20

I've been working on a little project that connects to the user's Gmail inbox and reads the mails using google-api-client 2.0.0 and google-api-services-gmail version v1-rev20220404-2.0.0

When I try to build the Gmail service

service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY,
          authorize).setApplicationName(Main.APPLICATION_NAME).build();

it throws an IllegalStateException that says

"You are currently running with version 2.0.0 of google-api-client. You need at least version 1.15 of google-api-client to run version 1.25.0 of the Gmail API library."

At first I thought that maybe the modules I installed weren't up to date or something but it didn't really make sense, so I tried debugging and got in the Gmail.java class.

The code checks for the version in a really simple way, if the condition is false then it throws the exception

static {
        Preconditions.checkState(GoogleUtils.MAJOR_VERSION == 1 && GoogleUtils.MINOR_VERSION >= 15,
        "You are currently running with version %s of google-api-client. You need at least version 1.15 of google-api-client to run version 1.25.0 of the Gmail API library.",
        new Object[]{GoogleUtils.VERSION});
    }

This is where the problem lies I think, my MAJOR_VERSION being 2 and MINOR_VERSION being 0 makes the statement false, even if the version I'm using is the latest. I have no idea if it can be solved by downgrading the API version to a 1.XX, I'll try anyway, but do you know if I'm onto something here?

0 Answers
Related