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.

Could not init mockmaker InlineStaticMockMaker neither InlineDexmakerMockMaker

See original GitHub issue

Hello,

I’m having an issue when mocking a class in an App module.

E/MockMakerMultiplexer: Could not init mockmaker com.android.dx.mockito.inline.InlineStaticMockMaker
W/.mockmakerissu: Agent attach failed (result=1) : Unable to dlopen libdexmakerjvmtiagent.so: dlopen failed: library "libdexmakerjvmtiagent.so" not found
E/MockMakerMultiplexer: Could not init mockmaker com.android.dx.mockito.inline.InlineDexmakerMockMaker
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at com.android.dx.mockito.inline.MockMakerMultiplexer.<clinit>(MockMakerMultiplexer.java:47)
        at java.lang.Class.newInstance(Native Method)
        ...
E/MockMakerMultiplexer:     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2251)
     Caused by: java.lang.RuntimeException: Could not initialize inline mock maker.
        at com.android.dx.mockito.inline.InlineDexmakerMockMaker.<init>(InlineDexmakerMockMaker.java:180)
        	... 53 more
     Caused by: java.lang.IllegalStateException: Mockito could not self-attach a jvmti agent to the current VM. This feature is required for inline mocking.
        at com.android.dx.mockito.inline.InlineDexmakerMockMaker.<clinit>(InlineDexmakerMockMaker.java:112)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at com.android.dx.mockito.inline.MockMakerMultiplexer.<clinit>(MockMakerMultiplexer.java:46)
        	... 50 more
     Caused by: java.io.IOException: Unable to dlopen libdexmakerjvmtiagent.so: dlopen failed: library "libdexmakerjvmtiagent.so" not found
        at dalvik.system.VMDebug.nativeAttachAgent(Native Method)
        at dalvik.system.VMDebug.attachAgent(VMDebug.java:591)
        at android.os.Debug.attachJvmtiAgent(Debug.java:2481)
        at com.android.dx.mockito.inline.JvmtiAgent.<init>(JvmtiAgent.java:65)
        at com.android.dx.mockito.inline.InlineDexmakerMockMaker.<clinit>(InlineDexmakerMockMaker.java:90)
        	... 54 more
        ...
Release: Android 10 10.0.0.196C69Device: HUAWEI ELE-L04
This error occured due to an I/O error during the creation of this agent: java.io.IOException: Unable to dlopen libdexmakerjvmtiagent.so: dlopen failed: library "libdexmakerjvmtiagent.so" not found

Potentially, the current VM does not support the jvmti API correctly

Causing this error:

E/TestRunner: java.lang.NullPointerException: Attempt to invoke interface method 'boolean org.mockito.plugins.MockMaker$TypeMockability.mockable()' on a null object reference
        at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:23)
        at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:240)
        at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:228)
        at org.mockito.internal.MockitoCore.mock(MockitoCore.java:61)
        at org.mockito.Mockito.mock(Mockito.java:1907)
        at org.mockito.Mockito.mock(Mockito.java:1816)
        ...

adb logcat

The weird thing is, it works in a Library module.

I created the following project with an app module and a library module to reproduce the issue: https://github.com/GianpaMX/MockMakerIssue

I’m running theses tests in an Android 10 device (HUAWEI ELE-L04)

This is very similar to #119 and #127

Thank you,

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kkosercommented, Jun 18, 2020

Hi @GianpaMX thanks much for reporting and for the sample project! I’m still digging into this bug - I’ve found the source of the problem, and am working on a proper fix.

The cause is the change to native library compression introduced in AGP 3.6 (https://developer.android.com/studio/releases/gradle-plugin#extractNativeLibs). This is resulting in the app not being able to find the native library it needs to connect to the JVMTI.

A workaround for now is to opt-out of that feature for your test APK using the android:extractNativeLibs="true" flag in the manifest. You can do this by placing an AndroidManifest.xml file in your androidTest/ folder, and it will be used for the android test apk.

I’ll keep this thread updated as we investigate a fix on the dexmaker side to make that unnecessary, but wanted to share it for now.

0reactions
yea978commented, Sep 8, 2021

Workaround above doesn’t work anymore.

The error is: error: existing attribute extractNativeLibs=“true” conflicts with --extract-native-libs=“false”

android:debuggable=“true” doesn’t help much as well

this conflict can be solved by using “use_embedded_native_libs: true” but you will see another error: “Mockito could not self-attach a jvmti agent to the current VM. This feature is required for inline mocking. This error occured due to an I/O error during the creation of this agent: java.io.IOException: Initialization of libdexmakerjvmtiagent.so returned non-zero value of -3”

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Cannot initialize MockMaker - Stack Overflow
MockMaker with mock-maker-inline inside. The test class fails because java.lang.IllegalStateException: Could not initialize plugin: interface ...
Read more >
Could not initialize plugin MockMaker - HowToDoInJava
The root cause of this error is the version mismatch between Mockito and ByteBuddy. For a few people, it turned out to be...
Read more >
Diff - platform/external/dexmaker - Google Git
One common case for this requirement is a mock class wanting to mock package * private methods of the original class. * +...
Read more >
A brand new website interface for an even better experience!
Could not init mockmaker InlineStaticMockMaker neither InlineDexmakerMockMaker.
Read more >
Java Mockito MockMaker isTypeMockable(Class<?> type)
Mockmaker may have different capabilities in term of mocking, typically Mockito 1.x's internal mockmaker cannot mock final types. Other implementations, may ...
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