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.

javax.tools.ToolProvider could not be found in InlineByteBuddyMockMaker

See original GitHub issue

Hi guys

I’m encountering a crash when I run AndroidTest that contain mocking class cause the ByteBuddy didn’t found javax.tools.ToolProvider. I tried to reinstall JDK 8 but doesn’t work. It seems to be javax.tools.ToolProvider not existing in it.

Could you guys help me please?

Cheer,

Natthawut

Environment


Gradle 5.4.1

Build time: 2019-04-26 08:14:42 UTC Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d

Kotlin: 1.3.21 Groovy: 2.5.4 Ant: Apache Ant™ version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_231 (Oracle Corporation 25.231-b11) OS: Mac OS X 10.15.2 x86_64

Dependencies

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:3.2.4'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'org.mockito:mockito-android:3.2.4'
    androidTestImplementation "io.mockk:mockk-android:1.9.3.kotlin12"

Strack trace

E/TestRunner: failed: mockFoo(co.sample.mockitoandroid.MockWithMockitoTest)
    ----- begin exception -----
E/TestRunner: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:74)
        at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
        at $Proxy3.isTypeMockable(Unknown Source)
        at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
        at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
        at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:241)
        at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:229)
        at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
        at org.mockito.Mockito.mock(Mockito.java:1908)
        at org.mockito.Mockito.mock(Mockito.java:1817)
        at co.sample.mockitoandroid.MockWithMockitoTest.<init>(MockWithMockitoTest.kt:17)
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
        at org.junit.runners.Suite.runChild(Suite.java:128)
        at org.junit.runners.Suite.runChild(Suite.java:27)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
        at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/tools/ToolProvider;
        at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:172)
        at java.lang.Class.newInstance(Native Method)
        at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:49)
        at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
        at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
        at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:22)
        at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:19)
        at org.mockito.internal.configuration.plugins.Plugins.getMockMaker(Plugins.java:35)
        at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:24)
        at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29) 
        at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22) 
        at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:241) 
        at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:229) 
        at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62) 
        at org.mockito.Mockito.mock(Mockito.java:1908) 
        at org.mockito.Mockito.mock(Mockito.java:1817) 
        at co.sample.mockitoandroid.MockWithMockitoTest.<init>(MockWithMockitoTest.kt:17) 
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
        at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217) 
        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) 
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) 
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
        at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104) 
        at org.junit.runners.Suite.runChild(Suite.java:128) 
        at org.junit.runners.Suite.runChild(Suite.java:27) 
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
        at org.junit.runner.JUnitCore.run(JUnitCore.java:115) 
        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56) 
        at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392) 
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.tools.ToolProvider" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/co.sample.mockitoandroid.test-ZJFawUg-
    ----- end exception -----
Screen Shot 2563-01-07 at 12 45 26

MockitoAndroid.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:17
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mitsestcommented, Jan 7, 2021

You can achieve this by using com.linkedin.dexmaker:dexmaker-mockito-inline for APIs >= 28

0reactions
raphwcommented, Jul 16, 2020

On Android, the inline mock maker won’t work (neither will Mockk which uses the same approach as we do). It does not support the instrumentation API alltogether.

I do agree that the error message is misleading. Currently preparing a PR to improve this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoClassDefFoundError: javax/tools/ToolProvider
Hello, I'm trying to install XGBoost4J from source on macOS 10.13.5, and get the following error: [ERROR] Caused by: java.lang.
Read more >
javax.tools.ToolProvider.getSystemJavaCompiler java code ...
Best Java code snippets using javax.tools. ... toString(); JavaCompiler compiler = ToolProvider. ... "Could not initialize inline Byte Buddy mock maker.
Read more >
Using javax.tools.ToolProvider from a custom classloader?
JavaCompiler into a URLClassLoader whose parent is the system classloader. The API does not seem to allow users to specify a parent classloader....
Read more >
Could not initialize inline Byte Buddy mock maker ... - YouTrack
Tests should behave like when running in Gradle What happens instead? tests crashes and gives: Could not initialize inline Byte Buddy mock maker....
Read more >
Compare ⋅ mockito/mockito - Codecov
No flags found. Use flags to group coverage reports by test type, project and/or folders. Then setup custom commit statuses and notifications for...
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