Commit 807e665
[monodroid] ensure main app assembly is loaded (#4058)
Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html
In a project where:
1. The `MainLauncher` activity is in a class library
2. This activity uses a value from `Resource.designer.cs`
You get a crash such as:
UNHANDLED EXCEPTION:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f09001c
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0
at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <82e50ec67af648c3b9f43b3d70e21b96>:0
at ClassLibrary1.SharedActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00011] in <aff3f2d8f15f4b618f6674d9c306f099>:0
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <82e50ec67af648c3b9f43b3d70e21b96>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
--- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281)
at android.content.res.Resources.getLayout(Resources.java:1175)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at crc64fd99288c2cd04dcf.SharedActivity.n_onCreate(Native Method)
at crc64fd99288c2cd04dcf.SharedActivity.onCreate(SharedActivity.java:30)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
In this example `App1.dll` is the main app assembly, but
`ClassLibrary1.SharedActivity` is the `MainLauncher`.
What was strange is that when I looked at the list of assemblies in
`AppDomain.CurrentDomain.GetAssemblies ()` before the failure,
`App1.dll` was not in the list!
So I enabled a bunch of logging:
adb shell setprop debug.mono.log default,assembly,timing
The log messages like this did not mention `App1.dll`:
I monodroid-assembly: open_from_update_dir: loaded assembly: 0x7723bca880
I monodroid-timing: Assembly load: ClassLibrary1.dll preloaded; elapsed: 0s:1::252032
Which lead me to this code:
/* skip element 0, as that's loaded in create_domain() */
for (size_t i = 1; i < assemblies.get_length (); ++i) {
I don't actually see anything in `create_domain()` that would load
`App1.dll`? Looking through the commit history I don't understand
how this project would have ever worked?
Changing `i = 1` to `i = 0` solves the crash in the project.
I added a test that reproduces the issue. I also added a
`DebuggingTest.SetTargetFrameworkAndManifest()` helper method to
cleanup `DebuggingTest.cs`.1 parent 87531bb commit 807e665
File tree
3 files changed
+75
-26
lines changed- Documentation/release-notes
- src/monodroid/jni
- tests/MSBuildDeviceIntegration/Tests
3 files changed
+75
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1354 | 1354 | | |
1355 | 1355 | | |
1356 | 1356 | | |
1357 | | - | |
1358 | | - | |
| 1357 | + | |
1359 | 1358 | | |
1360 | 1359 | | |
1361 | 1360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
21 | 33 | | |
22 | 34 | | |
23 | 35 | | |
| |||
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| |||
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
63 | 123 | | |
64 | 124 | | |
65 | 125 | | |
| |||
147 | 207 | | |
148 | 208 | | |
149 | 209 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 210 | + | |
158 | 211 | | |
159 | 212 | | |
160 | 213 | | |
| |||
281 | 334 | | |
282 | 335 | | |
283 | 336 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 337 | + | |
292 | 338 | | |
293 | 339 | | |
294 | 340 | | |
| |||
0 commit comments