java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets in Android API < 19

Open
#604 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, java
Domain
mobile-dev

Research direction

Start in StringUtils.java, especially getBytesUtf8 and newStringUtf8, which the stack trace identifies as failing on Android API <19. Reproduce the crash on an affected API level and trace the callers shown in JsonWebSignature.java and GoogleCredential.java. Done means these UTF-8 operations no longer load the unavailable StandardCharsets class on API 18 and below.

Written by the indexing model from the issue text.

Description

type: feature request

Hi,

we have problems with the latest version of your library in devices running Android 4.3 (API 18) or lower. StandardCharsets was added in Android API 19 so any call to methods using that (for example, StringUtils.getBytesUtf8 or StringUtils.newStringUtf8) causes a crash in our app.

Environment details
  • OS: Android API < 19
  • google-http-java-client version: 1.28
Stacktrace
    java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
        at com.google.api.client.util.StringUtils.getBytesUtf8(StringUtils.java:52)
        at com.google.api.client.json.webtoken.JsonWebSignature.signUsingRsaSha256(JsonWebSignature.java:636)
        at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:388)
        at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:494)
        at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217)
        at com.google.api.client.googleapis.batch.BatchRequest$BatchInterceptor.intercept(BatchRequest.java:281)
        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:911)
        at com.google.api.client.googleapis.batch.BatchRequest.execute(BatchRequest.java:233)
        at our.app.PubSubManager.sendTopic(PubSubManager.java:100)
        at java.lang.Thread.run(Thread.java:841)
Any additional information below

https://developer.android.com/reference/java/nio/charset/StandardCharsets.html

Thanks!

Dominant language
Java
Stars
1.4k
Forks
476
Avg merge
10h 47m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-http-java-client

All issues in googleapis/google-http-java-client

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.