Skip to content
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

Could not init mockmaker InlineStaticMockMaker neither InlineDexmakerMockMaker #164

Open
GianpaMX opened this issue May 31, 2020 · 8 comments
Labels

Comments

@GianpaMX
Copy link

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,

@chao2zhang chao2zhang added the bug label Jun 1, 2020
@kkoser
Copy link
Contributor

kkoser commented 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.

@GianpaMX
Copy link
Author

Awesome @kkoser,

I can confirm the workaround works

Thank you,

@kkoser
Copy link
Contributor

kkoser commented Jun 29, 2020

I wasn't able to find a solution for this, so I've opened https://issuetracker.google.com/u/1/issues/160108941 with the AGP team for this, hopefully they can provide some better guidance on a long term answer here.

@taeels
Copy link

taeels commented Aug 25, 2020

Hi,
I encountered similar errors while building test app on Q-AOSP with .bp

Since I'm working on AOSP, I started with including below library - Android version of dexmaker - to static :

...
static_libs: [
  "mockito-target-inline",
  ...,
],
jni_libs: ["libdexmakerjvmtiagent", "libstaticjvmtiagent"],
...

First time my app was able to extract .so files but could not attach libraries. (returned -3, which means JNI_EVERSION)
The solution was add android:debuggable="true" option to <application...> tag on AndroidManifest.xml
Because android mandates art runtime to attach JVMTI when only started with debuggable flag
Hope it would help some other person who'll come here later..

@icegood
Copy link

icegood commented Jul 6, 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

@icegood
Copy link

icegood commented Jul 6, 2021

07-06 14:23:25.456 3535 3555 D InfraTrack: Tracking disabled due to lack of internet permissions
07-06 14:23:25.456 3535 3555 I UsageTrackerFacilitator: Usage tracking disabled
07-06 14:23:25.464 3535 3555 D TestExecutor: Adding listener androidx.test.internal.runner.listener.LogRunListener
07-06 14:23:25.465 3535 3555 D TestExecutor: Adding listener androidx.test.internal.runner.listener.InstrumentationResultPrinter
07-06 14:23:25.465 3535 3555 D TestExecutor: Adding listener androidx.test.internal.runner.listener.ActivityFinisherRunListener
07-06 14:23:25.465 3535 3555 I TestRunner: run started: 1 tests
07-06 14:23:25.466 3535 3555 I TestRunner: started: wrapperStartDownload(com.scania.service.phoneorg.tests.instrumental.PBAPClientWrapperTest)
07-06 14:23:25.529 3535 3555 W ervice.phoneor: Agent attach failed (result=1) : Unable to dlopen libstaticjvmtiagent.so: dlopen failed: library "libstaticjvmtiagent.so" not found
07-06 14:23:25.529 3535 3555 E MockMakerMultiplexer: Could not init mockmaker com.android.dx.mockito.inline.InlineStaticMockMaker
07-06 14:23:25.530 3535 3555 W ervice.phoneor: Agent attach failed (result=1) : Unable to dlopen libdexmakerjvmtiagent.so: dlopen failed: library "libdexmakerjvmtiagent.so" not found
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: Could not init mockmaker com.android.dx.mockito.inline.InlineDexmakerMockMaker
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: java.lang.reflect.InvocationTargetException
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at java.lang.reflect.Constructor.newInstance0(Native Method)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at com.android.dx.mockito.inline.MockMakerMultiplexer.(MockMakerMultiplexer.java:47)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at java.lang.Class.newInstance(Native Method)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:49)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.configuration.plugins.PluginRegistry.(PluginRegistry.java:21)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.configuration.plugins.Plugins.(Plugins.java:18)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.configuration.plugins.Plugins.getMockMaker(Plugins.java:34)
07-06 14:23:25.532 3535 3555 E MockMakerMultiplexer: at org.mockito.internal.util.MockUtil.(MockUtil.java:24)

In my case target has no libstaticjvmtiagent.so on it's disks. How do I properly install it?

@yea978
Copy link

yea978 commented 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"

@binaykumarrana
Copy link

Hi, do we have any solution to this? I am trying to run unit tests with mockito but failing in 14 but all is fine in the lower version.
Please, suggest and help I need to push some with this fix. I tried the provided but didn't work also we don't use the androidTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants