-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
java.lang.NoSuchMethodError: org.json.JSONTokener.<init>(Ljava/io/Reader;)V #882
Comments
This appears to be duplicate of #867. Could you please try the workaround listed there and let us know if that doesn't work? We'll need to change the implementation on a future release to detect if this method is available on Android and then fallback to older logic if not. |
@lhazlewood I ran into the same issue described. I tried the proposed solution (not excluding the org.json dependency), and I still run into the same issue. It looks like it might of worked for someone else in #867, but it didn't solve it for me. |
@DanielGalarza thanks for trying the proposed solution. What version of Android are you using? @phamhongphong what version of Android are you using since it worked for you? |
@DanielGalarza just to confirm, your dependencies looked like this? dependencies {
api('io.jsonwebtoken:jjwt-api:0.12.3')
runtimeOnly('io.jsonwebtoken:jjwt-impl:0.12.3')
runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.12.3')
} |
@lhazlewood Not excluding org.json works, but I don't want to include it in our project because of maintainability. For now, we are going to stay in version 0.11.5. |
@ejoseca that's helpful, thanks for the feedback. We'll use this issue to track the work for a fix. |
@ejoseca which version of Android are you using? I'd like to ensure a fix is compatible with at least that (and potentially others). |
Actually, Android version probably doesn't matter, it appears that even the latest only supports a String constructor: https://developer.android.com/reference/org/json/JSONTokener#JSONTokener(java.lang.String) |
We support from Android 5 (SDK 21) onwards, but the JSON implementation is almost the same for all Android versions. JSONTokener in Android 2.3: https://android.googlesource.com/platform/libcore/+/refs/tags/android-2.3_r1/json/src/main/java/org/json/JSONTokener.java |
@lhazlewood Correct, that's what I tried to use, but still ran into issues. As far as the Android versions we are running, It's Android 8 (API 26) and through Android 14 (API 34) I will also be staying on v11.5 for now, but I am looking forward to a fix soon, so that I can migrate over to 12+ |
…SONTokener(Reader) constructor is not available. Closes #882
OrgJsonDeserializer: Added fallback implementation for Android when JSONTokener(Reader) constructor is not available. Closes #882
As updated by the PR merge, I've fixed this issue AFAICT. If anyone in this thread has the ability to build the latest |
This will be released in an upcoming |
@lhazlewood I'm happy to test this, but I'm not sure how to test you master branch. Is there a specific way I can do that from my Android project? Would this work:
|
@DanielGalarza you'd have to |
@DanielGalarza I believe it would look something like this after building JJWT locally via api("io.jsonwebtoken:jjwt-api:0.12.4-SNAPSHOT")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.4-SNAPSHOT")
runtimeOnly("io.jsonwebtoken:jjwt-orgjson:0.12.4-SNAPSHOT") {
exclude group: "org.json", module: "json" //provided by Android natively
} |
Description
JWS cannot be deserialized in Android devices.
Steps to reproduce
java.lang.NoSuchMethodError: org.json.JSONTokener.<init>(Ljava/io/Reader;)V
Cause
Since 0.12.0, the class
io.jsonwebtoken.orgjson.io.OrgJsonDeserializer
, in itsparse()
method, is trying to create aJSONTokener
passing aReader
as argument to the constructor.This constructor is not available in the Android implementation of
JSONTokener
: https://android.googlesource.com/platform/libcore/+/refs/heads/main/json/src/main/java/org/json/JSONTokener.javaThe text was updated successfully, but these errors were encountered: