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.

java.lang.NoClassDefFoundError: org.mockito.internal.util.MockCreationValidator

See original GitHub issue

Explanation:

Swapping out Google’s dexmaker with LinkedIn’s dexmaker, I am getting the following error. From what I can tell, the LinkedIn version of the dexmaker is so much larger that it causes the Android Test APK to become Multidex.

I have tried the following: https://stackoverflow.com/questions/30081386/how-to-put-specific-classes-into-main-dex-file and https://stackoverflow.com/questions/34310259/trying-to-test-an-android-module-in-multidex-app-com-android-test-runner-multid.

Any way to avoid this?

Error:

D/AndroidRuntime( 2960): Shutting down VM
    E/AndroidRuntime( 2970): FATAL EXCEPTION: main
    E/AndroidRuntime( 2970): Process: <>, PID: 2970
    E/AndroidRuntime( 2970): java.lang.NoClassDefFoundError: org.mockito.internal.util.MockCreationValidator
    E/AndroidRuntime( 2970): 	at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:166)
    E/AndroidRuntime( 2970): 	at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:162)
    E/AndroidRuntime( 2970): 	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
    E/AndroidRuntime( 2970): 	at org.mockito.Mockito.mock(Mockito.java:1637)
    E/AndroidRuntime( 2970): 	at org.mockito.Mockito.mock(Mockito.java:1550)
    ...
    E/AndroidRuntime( 2970): 	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
    ...
    E/AndroidRuntime( 2970): 	at dagger.internal.DoubleCheck.get(DoubleCheck.java:47)
    ...
    E/AndroidRuntime( 2970): 	at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
    E/AndroidRuntime( 2970): 	at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:323)
    E/AndroidRuntime( 2970): 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
    E/AndroidRuntime( 2970): 	at android.app.ActivityThread.access$1500(ActivityThread.java:135)
    E/AndroidRuntime( 2970): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    E/AndroidRuntime( 2970): 	at android.os.Handler.dispatchMessage(Handler.java:102)
    E/AndroidRuntime( 2970): 	at android.os.Looper.loop(Looper.java:136)
    E/AndroidRuntime( 2970): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
    E/AndroidRuntime( 2970): 	at java.lang.reflect.Method.invokeNative(Native Method)
    E/AndroidRuntime( 2970): 	at java.lang.reflect.Method.invoke(Method.java:515)
    E/AndroidRuntime( 2970): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    E/AndroidRuntime( 2970): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    E/AndroidRuntime( 2970): 	at dalvik.system.NativeStart.main(Native Method)

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
tmurakamicommented, Jun 7, 2017

Hi.

@jaredsburrows, DexMaker has its own MockMaker, so I think that you can exclude Byte Buddy from your test apk.

dependencies {
    androidTestCompile('com.linkedin.dexmaker:dexmaker-mockito:x.y.z') {
        exclude group: 'net.bytebuddy'
    }
}
1reaction
tmurakamicommented, Jun 10, 2017

@jaredsburrows,

dependencies {

    // For local unit tests (on your develop machine)
    testCompile 'org.mockito:mockito-inline:2.8.9'

    // For instrumented unit tests (on Android emulators and devices)
    androidTestCompile('com.linkedin.dexmaker:dexmaker-mockito:2.2.0') {
        exclude group: 'net.bytebuddy'
    }

}

Running ./gradlew androidDependencies with the above code will get the following result.

$ ./gradlew androidDependencies
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to /home/tmura/android-sdk-linux/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use the method ConfigurableReport.setDestination(File) instead.
:app:androidDependencies
debug
No dependencies

debugAndroidTest
\--- com.linkedin.dexmaker:dexmaker-mockito:2.2.0@jar
     +--- com.linkedin.dexmaker:dexmaker:2.2.0@jar
     |    \--- com.jakewharton.android.repackaged:dalvik-dx:7.1.0_r7@jar
     |         \--- com.jakewharton.android.repackaged:libcore-dex:7.1.0_r7@jar
     \--- org.mockito:mockito-core:2.2.29@jar
          \--- org.objenesis:objenesis:2.4@jar

debugUnitTest
\--- org.mockito:mockito-inline:2.8.9@jar
     \--- org.mockito:mockito-core:2.8.9@jar
          +--- net.bytebuddy:byte-buddy:1.6.14@jar
          +--- net.bytebuddy:byte-buddy-agent:1.6.14@jar
          \--- org.objenesis:objenesis:2.5@jar

release
No dependencies

releaseUnitTest
\--- org.mockito:mockito-inline:2.8.9@jar
     \--- org.mockito:mockito-core:2.8.9@jar
          +--- net.bytebuddy:byte-buddy:1.6.14@jar
          +--- net.bytebuddy:byte-buddy-agent:1.6.14@jar
          \--- org.objenesis:objenesis:2.5@jar

BUILD SUCCESSFUL in 7s
1 actionable task: 1 executed, 0 avoided (0%)

Byte Buddy is used for MockMaker of Mockito, so it is required for local unit testing. However, since DexMaker has its own MockMaker which does not rely on Byte Buddy, it can be excluded from dependencies scoped as androidTestCompile.

FYI, Mockito does not support mock final on Android.

https://static.javadoc.io/org.mockito/mockito-core/2.8.9/org/mockito/Mockito.html#0.1

Be aware that you cannot use the inline mock maker on Android due to limitations in the Android VM.

Because inline mock maker relies on the java.lang.instrument API which Android does not support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoClassDefFoundError: org/objenesis/ObjenesisStd ...
ClassNotFoundException is result of a class loader that is not able to load a particular class. In your case Mockito has a transitive ......
Read more >
mockito failure [Solved] (Testing forum at Coderanch)
java.lang.NoClassDefFoundError: org/objenesis/ObjenesisStd. at org.mockito.internal.creation.jmock.ClassImposterizer.<init>(ClassImposterizer.java: 36 ).
Read more >
java.lang.NoClassDefFoundError: org.mockito.internal.util ...
Swapping out Google's dexmaker with LinkedIn's dexmaker, I am getting the following error. From what I can tell, the LinkedIn version of the...
Read more >
org.mockito.internal.configuration.InjectingAnnotationEngine
I'm trying to get PowerMock 1.4 working with Mockito 1.8.1. I've tried the SystemClassUser example like package com.googlecode.janrain4j.internal.http;
Read more >
NoClassDefFoundError on CI but works locally
java.lang.NoClassDefFoundError: Could not initialize class org.mockito.Answers at java.base/jdk.internal.reflect.
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