Commit 1b3f797
committed
[One .NET] fix $(AndroidEnablePreloadAssemblies) default
The `ClassLibraryMainLauncherRuns` test was crashing on app start with:
Java.Lang.RuntimeException: Unable to start activity ComponentInfo{com.xamarin.classlibrarymainlauncherruns/com.xamarin.classlibrarymainlauncherruns.MainActivity}: android.view.InflateException: Binary XML file line #1 in com.xamarin.classlibrarymainlauncherruns:layout/foo: Binary XML file line #1: You must supply a layout_width attribute.
---> Android.Views.InflateException: Binary XML file line #1 in com.xamarin.classlibrarymainlauncherruns:layout/foo: Binary XML file line #1: You must supply a layout_width attribute.
---> Java.Lang.UnsupportedOperationException: Binary XML file line #1: You must supply a layout_width attribute.
--- End of managed Java.Lang.UnsupportedOperationException stack trace ---
java.lang.UnsupportedOperationException: Binary XML file line #1: You must supply a layout_width attribute.
It seems like this would have always been broken, so I'm not exactly
sure how it is passing in some cases?
I fixed `foo.xml` so it was valid, and then I got a
`NullReferenceException` at startup instead!
Process: com.xamarin.classlibrarymainlauncherruns, PID: 2993
android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
at MyLibrary.MainActivity.OnCreate(Bundle bundle)
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
at com.xamarin.classlibrarymainlauncherruns.MainActivity.n_onCreate(Native Method)
at com.xamarin.classlibrarymainlauncherruns.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
When I looked closer, it seemed that `foo.xml` shouldn't be used at
runtime at all.
Thinking about this test:
1. `MyApp.dll` has no activity.
2. `MyLibrary.dll` has the main activity & layouts.
It made me think the change to `$(AndroidEnablePreloadAssemblies)` in
d13d0f9 might be at fault here.
To solve the issue:
1. Leave `$(_AndroidEnablePreloadAssembliesDefault)` set to `true`. I
think this is the default the runtime expects, and not the default
value of `$(AndroidEnablePreloadAssemblies)`.
2. Conditionally set a default for `$(AndroidEnablePreloadAssemblies)`
that is different for .NET 6 vs legacy.
3. Set `AndroidEnablePreloadAssemblies=true` in the test. This is a
case where I don't know how the runtime would know how to load
`MyLibrary.dll` otherwise.
I fixed `foo.xml` anyway, because it caused confusion.1 parent 28f4a06 commit 1b3f797
File tree
2 files changed
+12
-4
lines changed- src/Xamarin.Android.Build.Tasks
- tests/MSBuildDeviceIntegration/Tests
2 files changed
+12
-4
lines changedLines changed: 4 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
292 | 294 | | |
293 | | - | |
294 | | - | |
295 | | - | |
| 295 | + | |
| 296 | + | |
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
| |||
0 commit comments