mockk / mockk

mocking library for Kotlin
https://mockk.io
Apache License 2.0
5.34k stars 335 forks source link

io.mockk.proxy.MockKAgentException in android compose project test, mockk Version:1.13.11 #1273

Open dilkw opened 1 week ago

dilkw commented 1 week ago

When I upgraded AGP and Gradle to 8.5.0 and 8.7 respectively, the following error occurred when executing the test task:

java.lang.ExceptionInInitializerError at xxx.xxx.xxx.LoginScreenKtTest.(LoginScreenKtTest.kt:293) ... 33 trimmed Caused by: io.mockk.proxy.MockKAgentException: MockK 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: Unable to dlopen libmockkjvmtiagent.so: dlopen failed: library "libmockkjvmtiagent.so" not found

Potentially, the current VM does not support the jvmti API correctly at io.mockk.proxy.android.AndroidMockKAgentFactory.init(AndroidMockKAgentFactory.kt:67) at io.mockk.impl.JvmMockKGateway.(JvmMockKGateway.kt:46) at io.mockk.impl.JvmMockKGateway.(JvmMockKGateway.kt:185) ... 35 more Caused by: java.io.IOException: Unable to dlopen libmockkjvmtiagent.so: dlopen failed: library "libmockkjvmtiagent.so" not found at dalvik.system.VMDebug.nativeAttachAgent(Native Method) at dalvik.system.VMDebug.attachAgent(VMDebug.java:570) at android.os.Debug.attachJvmtiAgent(Debug.java:2481) at io.mockk.proxy.android.JvmtiAgent.(JvmtiAgent.kt:48) at io.mockk.proxy.android.AndroidMockKAgentFactory.init(AndroidMockKAgentFactory.kt:40) ... 37 more

mockk version: mockk = "1.13.11" mockkAndroid = "1.13.11"

android: AGP:8.5.0 Gradle:8.7

But when I try to add the following configuration in build.gradle, I can solve the current problem, but this should not be the most correct solution: android { testOptions { packaging { jniLibs { useLegacyPackaging = true } } } }