Commit 66312f7
[Java.Interop.Tools.JavaCallableWrappers] Improve missing attribute (#1369)
Context: bc44f08
If "something goes wrong" and the `*.jlo.xml` files contain
`//jcw-types/type` elements that are *missing* the `//type/@package`
attribute, then an exception is thrown:
System.InvalidOperationException: Missing required attribute 'package'
at Java.Interop.Tools.JavaCallableWrappers.Extensions.XmlExtensions.GetRequiredAttribute(XElement xml, String name)
at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.ImportType(XElement xml)
at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.Import(XElement xml)
at Xamarin.Android.Tasks.JavaObjectsXmlFile.Import(String filename, JavaObjectsXmlFileReadType readType)
at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.GenerateWrappers(List`1 assemblies)
at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.RunTask()
at Microsoft.Android.Build.Tasks.AndroidTask.Execute()
Which is all well and good, except ***I have no idea what's broken***.
*Something* within dotnet/android should be updated so that the file
causing the exception is mentioned, but we can also improve the
`InvalidOperationException` to contain at least a "breadcrumb" for
what's going wrong.
Update the `InvalidOperationException` to also include the contents
of the `XElement.ToString()` which is missing the required attribute.
We can then at least search file contents to find the "offending" file.
This provides a more useful exception message:
System.InvalidOperationException: Missing required attribute 'package' within element `<type name="SKCanvasElementImpl" package="" application_java_class="android.support.multidex.MultiDexApplication" mono_runtime_initialization="mono.MonoPackageManager.LoadApplication (context);" extends_type="Uno.WinUI.Graphics2DSK.SKCanvasElement" partial_assembly_qualified_name="SKCanvasElementImpl, SamplesApp">
<constructors>
<constructor name="SKCanvasElementImpl" method="n_.ctor:(Landroid/content/Context;)V:" jni_signature="(Landroid/content/Context;)V" managed_parameters="Android.Content.Context, Mono.Android" params="android.content.Context p0" retval="void" is_dynamically_registered="True" super_call="p0" activate_call="p0" />
</constructors>
</type>`.
at Java.Interop.Tools.JavaCallableWrappers.Extensions.XmlExtensions.GetRequiredAttribute(XElement xml, String name)
at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.ImportType(XElement xml)
at Java.Interop.Tools.JavaCallableWrappers.Adapters.XmlImporter.Import(XElement xml)
at Xamarin.Android.Tasks.JavaObjectsXmlFile.Import(String filename, JavaObjectsXmlFileReadType readType)
at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.GenerateWrappers(List`1 assemblies)
at Xamarin.Android.Tasks.GenerateJavaCallableWrappers.RunTask()
at Microsoft.Android.Build.Tasks.AndroidTask.Execute()
Which shows *two* problems:
1. The `package` attribute *is* present, but
2. The `package` attribute is the empty string.
Which should be supported! The global package is A Thing That Exists™;
it should be supported! (Has *been* supported?!)
Update `XmlImporter.ImportType()` so that `package` is *not* required.
Update `tests/Java.Interop.Tools.JavaCallableWrappers-Tests` to add
an explicit test for a type in the Java global package.1 parent 0b7b3e9 commit 66312f7
File tree
4 files changed
+11
-3
lines changed- src/Java.Interop.Tools.JavaCallableWrappers
- Extensions
- Java.Interop.Tools.JavaCallableWrappers.Adapters
- tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers
4 files changed
+11
-3
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| 140 | + | |
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
| |||
0 commit comments