Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.
- Loading branch information