Skip to content

Fix JvmtiAgent native library load when extractNativeLibs=false#210

Open
jselbo wants to merge 1 commit intolinkedin:mainfrom
jselbo:fix-jvmtiagent-extractnativelibs
Open

Fix JvmtiAgent native library load when extractNativeLibs=false#210
jselbo wants to merge 1 commit intolinkedin:mainfrom
jselbo:fix-jvmtiagent-extractnativelibs

Conversation

@jselbo
Copy link

@jselbo jselbo commented Mar 5, 2026

Fixes #164

Debug.attachJvmtiAgent with a bare library name fails when extractNativeLibs=false (the AGP default for minSdk >= 23) because the .so is stored inside the APK rather than extracted to disk. The JVMTI agent loading path in ART uses OpenNativeLibrary with filesystem-only search paths, unlike System.loadLibrary which can load directly from APK via the linker namespace. This seems like a bug in the Android jvmti agent code.

Resolve the library path via BaseDexClassLoader.findLibrary() first. If the resolved path contains '=' (common in base64-encoded app install directories), copy the library to a temp file since Debug.attachJvmtiAgent rejects paths with '='. If findLibrary returns null, extract the library from classloader resources to a temp file.

To verify this, I configured a test app with minSdk >= 23 and without android:extractNativeLibs=true. With this fix, the agent now attaches and the mock maker works as expected.

Debug.attachJvmtiAgent with a bare library name fails when
extractNativeLibs=false (the AGP default for minSdk >= 23) because the
.so is stored inside the APK rather than extracted to disk. The JVMTI
agent loading path in ART uses OpenNativeLibrary with filesystem-only
search paths, unlike System.loadLibrary which can load directly from
APK via the linker namespace.

Resolve the library path via BaseDexClassLoader.findLibrary() first. If
the resolved path contains '=' (common in base64-encoded app install
directories), copy the library to a temp file since
Debug.attachJvmtiAgent rejects paths with '='. If findLibrary returns
null, extract the library from classloader resources to a temp file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Could not init mockmaker InlineStaticMockMaker neither InlineDexmakerMockMaker

1 participant