Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api 19 Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets #926

Closed
Zevsus opened this issue Dec 24, 2019 · 10 comments
Assignees
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.

Comments

@Zevsus
Copy link

Zevsus commented Dec 24, 2019

Environment details

  1. OS type and version: Android api 19
  2. Java version: 8
  3. google-http-client version(s): implementation 'com.google.http-client:google-http-client-gson:1.34.0'

Code example

private static List exeQ(String q) throws IOException {
String nextPageToken = "";
List res = new ArrayList<>();
do {
final FileList list = googleDriveService.files().list().setSpaces("drive").setQ(q).setPageToken(nextPageToken).setFields("nextPageToken, files(*)").setPageSize(100).setOrderBy("modifiedTime").execute();
nextPageToken = list.getNextPageToken();
res.addAll(list.getFiles());
} while (nextPageToken != null);
return res;
}

Stack trace

     Caused by: java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
        at com.google.api.client.util.escape.CharEscapers.decodeUriPath(CharEscapers.java:110)
        at com.google.api.client.http.GenericUrl.toPathParts(GenericUrl.java:594)
        at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:200)
        at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:177)
        at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:126)
        at com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:109)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequestUrl(AbstractGoogleClientRequest.java:388)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:423)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:542)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:475)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:592)
        (GFile.java:192)

Thanks!

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Dec 25, 2019
@codyoss
Copy link
Member

codyoss commented Dec 26, 2019

From what I can tell StandardCharsets was added in with api level 19, so this should work.
Ref: https://developer.android.com/reference/java/nio/charset/StandardCharsets.html

@codyoss codyoss added type: question Request for information or clarification. Not an issue. needs more info This issue needs more information from the customer to proceed. and removed triage me I really want to be triaged. labels Dec 26, 2019
@Zevsus
Copy link
Author

Zevsus commented Jan 4, 2020

But it crashes - in the previous version this was not.

@codyoss
Copy link
Member

codyoss commented Jan 6, 2020

Is your target >19?

@insightfulfellow
Copy link

I have the same problem. The min required API has not changed, but now it depends on
java.nio.charset.StandardCharsets which requires API > 19. This dependency should be removed.

@elharo
Copy link
Contributor

elharo commented Jan 31, 2020

Per android docs, java.nio.charset.StandardCharsets was added in API 19, and requires API >= 19, not strictly greater than 19:

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

Are you stating that the docs are wrong? (Entirely possible, of course, but I want to make sure there isn't some other confusion here.)

@3c71
Copy link

3c71 commented Mar 20, 2020

2 weeks ago I was able to use this API on Android 4.2, but now I get this error. Is this API no longer supporting API below 19?

@elharo
Copy link
Contributor

elharo commented Mar 31, 2020

Correct. We do not support Android before 4.4.

@elharo elharo closed this as completed Mar 31, 2020
@3c71
Copy link

3c71 commented Mar 31, 2020

It seems the library does not support Android before 4.4 only because of this charset class missing that was added in API 19 which only an UTF8 name?

Anyway I reverted to version 1.33.0 of httpclient and version 1.30.1 of apiclient and "all is good" now and it appears to be working on all Android 4.x. Is that correct assumption?

Wouldn't it be possible to include the minimum SDK in the library so we get a warning if we target a lower SDK? Other libraries are doing so and it could avoid bad surprises in production.

@elharo
Copy link
Contributor

elharo commented Mar 31, 2020

I'm not sure. I'm hardly an expert in Android. Is there some standard way to do this? E.g. by adding a property to MANIFEST.MF or some such?

@3c71
Copy link

3c71 commented Mar 31, 2020

Sure there is a minSdk="" in AndroidManifest.xml that exists for any Android module, apps or libraries.

As a matter of fact I looked at https://github.com/googleapis/google-http-java-client/blob/master/google-http-client-android/AndroidManifest.xml

and it shows this:
android:minSdkVersion="4"
android:targetSdkVersion="4"

It should read 14 and not 4. I suppose other libraries are affected the same way but I didn't check.

No wonder there is no warning or error.

clundin25 pushed a commit to clundin25/google-http-java-client that referenced this issue Aug 11, 2022
…e-plugin to v3.0.0-m7 (googleapis#926)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [org.apache.maven.plugins:maven-surefire-plugin](https://maven.apache.org/surefire/) | `3.0.0-M6` -> `3.0.0-M7` | [![age](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M7/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M7/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M7/compatibility-slim/3.0.0-M6)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/org.apache.maven.plugins:maven-surefire-plugin/3.0.0-M7/confidence-slim/3.0.0-M6)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. ⚠ **Warning**: custom changes will be lost.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/google-auth-library-java).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants