Skip to content

Android: Load class with DexClassLoader

For app that targets Android 11 (API level 30) or higher and queries for information about the other apps that are installed on a device, the system filters this information by default. App must declare package visibility needs, either by <queries> or android.permission.QUERY_ALL_PACKAGES. This change will cause the client library is not able to load Java class from runtime package, NameNotFoundException would be thorwn when trying to get runtime information.

1st commit uses DexClassLoader to load Java classes from runtime apk. By using dladdr, it bypass the need of <queries> and returns pathname of shared object that contains address. This might be hacky, but it works now.

2nd and 3rd commits fix an issue that android device driver failed to get display metrics due to invalid context. In service side, context is not stored so an error is thrownn. Adding some JNI code and replace Activity with Context, so it could work on service side with Context.

Tested with HelloXR which targetSdkVersion is set to 31. Tested on Pixel 2 (Android 11), Pixel 4 (Android 13) and HelloXR is working fine. I'll like to do more tests to confirm that this also works when runtime is installed from play store. But for debugging purpose, it's working now.

Edited by Jarvis Huang

Merge request reports