RikkaApps / Shizuku-API

The API and the developer guide for Shizuku and Sui.
MIT License
950 stars 223 forks source link

Set target classloader as thread classloader #79

Closed Evengard closed 5 months ago

Evengard commented 6 months ago

This is needed when the JNI itself attempts to resolve Java classes in the target Service, aka using JNIEnv.FindClass.

Namely, this helps with DotNet MAUI apps not loading in the Shizuku context and crashing with GetClassGRef: class net/dot/android/crypto/DotnetProxyTrustManager was not found in logcat.

vvb2060 commented 5 months ago

The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());

more info https://cs.android.com/android/platform/superproject/+/main:frameworks/base/core/java/android/app/LoadedApk.java;l=1189

Evengard commented 5 months ago

I see, I can add similar checks here, let me do this during the evening.