Commit 6611420
committed
Use Class.ForName(String, boolean, ClassLoader)
Context: dotnet/android#9931
Context: dotnet/android#9931 (comment)
The attempted integration test crashed!
F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.ClassNotFoundException: Didn't find class "crc641855b07eca6dcc03.MyCb" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
F mono-rt : at Java.Interop.JniEnvironment.Types.TryFindClass(String classname, Boolean throwOnError)
F mono-rt : at Java.Interop.JniEnvironment.Types.FindClass(String classname)
F mono-rt : at Java.Interop.JniType..ctor(String classname)
F mono-rt : at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type declaringType)
F mono-rt : at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type declaringType)
F mono-rt : at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String constructorSignature, Type declaringType, JniArgumentValue* parameters)
F mono-rt : at Java.Lang.Object..ctor()
F mono-rt : at Java.InteropTests.MyCb..ctor()
F mono-rt : at Java.InteropTests.JnienvTest.<>c__DisplayClass29_0.<DoNotLeakWeakReferences>b__1()
F mono-rt : at System.Threading.Thread.StartHelper.Callback(Object state)
F mono-rt : at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
F mono-rt : --- End of stack trace from previous location ---
F mono-rt : at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
F mono-rt : --- End of managed Java.Lang.ClassNotFoundException stack trace ---
F mono-rt : java.lang.ClassNotFoundException: Didn't find class "crc641855b07eca6dcc03.MyCb" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
F mono-rt : at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
F mono-rt : at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
F mono-rt : at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
Perhaps unsurprisingly, we need to provide the system ClassLoader
in order to load types from outside the default "classpath", which is
why we used `ClassLoader.loadClass()` in the first place.
Instead of `Class.forName()`, use the
[`Class.forName(String name, boolean initialize, ClassLoader loader)`][0]
overload, so that we can provide a `ClassLoader` instance.
This *should* fix the crash.
[0]: https://developer.android.com/reference/java/lang/Class#forName(java.lang.String,%20boolean,%20java.lang.ClassLoader)1 parent b8e729f commit 6611420
File tree
2 files changed
+16
-4
lines changed- src/Java.Interop/Java.Interop
2 files changed
+16
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
157 | | - | |
158 | 156 | | |
159 | 157 | | |
160 | 158 | | |
| |||
207 | 205 | | |
208 | 206 | | |
209 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
210 | 220 | | |
211 | 221 | | |
212 | 222 | | |
| |||
0 commit comments