Android google calendar api not working when in release

I use the Google Calendar api to get events from the shared calendar. In the Google developer console, I created a service account key (json), which I use to configure GoogleCredential in Android code as follows:

AssetManager am = getAssets(); InputStream inputStream = am.open("key-file-name.json"); GoogleCredential credential = GoogleCredential.fromStream(inputStream); credential =credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/calendar.readonly")); 

Then I use this GoogleCredential to get the calendar object

 Calendar client = new Calendar.Builder(AndroidHttp.newCompatibleTransport(), new JacksonFactory(), credential).setApplicationName("someAppName").build(); 

Then I get the following 5 events from this calendar

  com.google.api.services.calendar.model.Events nextEvent = client.events().list(" public-calendar-id@group.calendar.google.com ") .setTimeMin(new DateTime(new java.util.Date(), java.util.TimeZone.getDefault())) .setMaxResults(5) .setOrderBy("startTime") .setSingleEvents(true) .setShowDeleted(false) .execute(); 

Although this code works fine when debugging when working in android studio, when I create for release (a sign with a keystore file), it does not work. It simply returns the following exception:

com.google.aacbc: 404 Not found 3097-3187 / com.news.apoelnews W / System.err: Not found 3097-3187 / com.news.apoelnews W / System.err:
at com.google.aacdacb (Unknown source)

Please, help!

UPDATE I added the use of the Android API to the code as follows:

 com.google.api.services.calendar.model.Events nextEvent = client.events().list(" public-calendar-id@group.calendar.google.com ") .setTimeMin(new DateTime(new java.util.Date(), java.util.TimeZone.getDefault())) .setMaxResults(5) .setOrderBy("startTime") .setSingleEvents(true) .setShowDeleted(false) .setKey("api-key-string_from_developer_console")) .execute(); 

This throws the following exception:

W. / System.err: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden W / System.err: "code": 403, W / System.err: "errors": [{W / System. err: "domain": "usageLimits", W / System.err:
"message": "There is a limit for each IP address or each referrer to your API key, and the request does not meet these restrictions.

Note that API keys are created using debugging and SHA-1 release.

+5
source share
3 answers

The problem was during build in the version, the gradle option "minifyenable true" used google api class names. So the solution should include: -keep class com.google.api. ** {*; } in proguard

+6
source

Is api / Key generated for Signed Keystore and has the api key changed in the ur project that matches your Keystore release

0
source

I don't know much about Google Calendar Api, but Have you tried generating a SHA-1 key with your keystore? if you want to generate release apk, then you need to create a new key for Google Calendar and release it again, it will work for you.

follow these useful links: https://developer.android.com/studio/publish/app-signing.html#releasemode

https://coderwall.com/p/r09hoq/android-generate-release-debug-keystores

try

0
source

Source: https://habr.com/ru/post/1241943/


All Articles