I’m having trouble with the Google Calendar API when I build my Android app for production. Everything works perfectly in debug mode but breaks when I create a release build.
My Setup
I’m trying to fetch events from a public calendar using a service account. Here’s how I initialize the credentials:
AssetManager assets = getAssets();
InputStream credentialStream = assets.open("service-account.json");
GoogleCredential auth = GoogleCredential.fromStream(credentialStream);
auth = auth.createScoped(Collections.singletonList("https://www.googleapis.com/auth/calendar.readonly"));
Building the Calendar Client
Calendar calendarService = new Calendar.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(),
auth
).setApplicationName("MyCalendarApp").build();
Fetching Events
com.google.api.services.calendar.model.Events upcomingEvents =
calendarService.events().list("[email protected]")
.setTimeMin(new DateTime(new Date(), TimeZone.getDefault()))
.setMaxResults(10)
.setOrderBy("startTime")
.setSingleEvents(true)
.setShowDeleted(false)
.execute();
The Problem
In debug mode, this works great. But when I sign the APK for release, I get a 404 error. I also tried adding an API key, but then I received a 403 error about IP restrictions, even though I configured both debug and release SHA-1 fingerprints in the console.
Has anyone else run into this issue? What am I missing for production builds?