4

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?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449

2 Answers2

1

Solution is to upgrade to the v1-rev20230206-2.0.0 which is the latest version as of this writing

<dependency>
   <groupId>com.google.apis</groupId>
   <artifactId>google-api-services-gmail</artifactId>
   <version>v1-rev20230206-2.0.0</version>
</dependency>

Google documentation recommends searching for the lastest version here

Dave B
  • 459
  • 5
  • 10
0

In case this helps anyone else, I encountered this error when upgrading the Firebase Admin plugin. It prevented my App Engine app from starting up.

A simple fix for me was to revert my POM file.

Fix: downgrade 9.1.1 to 8.1.0:

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>9.1.1</version>
</dependency>

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>8.1.0</version>
</dependency>
Steve Neal
  • 756
  • 3
  • 8
  • 16