question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android Project Throwing io.jsonwebtoken.lang.UnknownClassException

See original GitHub issue

I’ve setup my project according to the directions. My build.gradle is essentially the following:

dependencies {
    implementation fileTree(dir:'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
    implementation "com.auth0.android:jwtdecode:1.4.0"
    implementation "com.google.code.gson:gson:2.8.6"

    testImplementation 'junit:junit:4.13'
    testImplementation "io.mockk:mockk:1.10.0"
    api 'io.jsonwebtoken:jjwt-api:0.11.2'
    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
    runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.2') {
        exclude group: 'org.json', module: 'json' //provided by Android natively
    }

}

I am only trying to use this library to generate a JWT in the proper format so that I can unit test my JWT parser. I’ve created an incredibly simple function to generate the JWT:

    private fun createJwtToken(): String {
        val key: Key = Keys.secretKeyFor(SignatureAlgorithm.HS256)
        return Jwts.builder().setSubject("Joe").signWith(key).compact()
}

However, I get the following crash the moment that I run my unit test:

java.lang.IllegalStateException: Unable to invoke class method io.jsonwebtoken.impl.crypto.MacProvider#generateKey.  Ensure the necessary implementation is in the runtime classpath.

	at io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:202)
	at io.jsonwebtoken.security.Keys.secretKeyFor(Keys.java:136)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: io.jsonwebtoken.lang.UnknownClassException: Unable to load class named [io.jsonwebtoken.impl.crypto.MacProvider] from the thread context, current, or system/application ClassLoaders.  All heuristics have been exhausted.  Class could not be found.  Have you remembered to include the jjwt-impl.jar in your runtime classpath?
	at io.jsonwebtoken.lang.Classes.forName(Classes.java:92)
	at io.jsonwebtoken.lang.Classes.invokeStatic(Classes.java:195)
	... 29 more

Everywhere that I’ve looked regarding this issue, the solution seems to always be that I need to ensure I’ve setup my Gradle dependencies correctly. However, I feel that I’ve done that and I’m still running into issues. Please let me know if additional information is needed.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mikepalarzcommented, Aug 13, 2020

Understandable @lhazlewood , thanks for the feedback. I do agree that this was likely due to my particular environment in some way.

0reactions
lhazlewoodcommented, Aug 12, 2020

@mikepalarz thanks for the update. Based on this, I’ll close this issue as it seems highly likely this is based on your local environment. If not and you find otherwise - no worries! I’m happy to re-open this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to find an implementation for interface io ... - GitHub
Hi guys, We are seeing this error: Unable to find an implementation for interface io.jsonwebtoken.io.Serializer using java.util.
Read more >
Difficulty importing JWT (JSON Web Token) in Spring Boot ...
How can I successfully import JSON web token into my gradle project (or at least import io). The method from the video tutorial...
Read more >
jwtk - Bountysource
Returning null is not handled by the calling code in JJWT, so it appears the correct thing to do is throw an exception....
Read more >
io.jsonwebtoken.lang.UnknownClassException Maven ...
UnknownClassException maven / gradle build tool code. The class is part of the package ➦ Group: io.jsonwebtoken ➦ Artifact: jjwt-api ➦ Version: 0.10.5....
Read more >
Gradle tips and recipes - Android Developers
Gradle tips and recipes ; Manage projects and sources. Change default source set configurations; Configure project-wide properties ; Manage libraries and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found