dotnet / java-interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Other
201 stars 53 forks source link

Bindingsgenerator stops recognizing C# types #543

Closed MFinkBK closed 4 years ago

MFinkBK commented 4 years ago

I have a bindings project where we bind a Brother Printer SDK library. Starting with VS 2019 16.4.0 we get warnings about missing managed types. This is the first line of about 30:

warning BG8800: Unknown parameter type System.Collections.Generic.IList<Java.Util.Locale.LanguageRange> in method Filter in managed type Java.Util.Locale.

Compiling and linking with the app project works fine, no further warnings. I can attach the whole log if needed.

I checked the msbuild output and saw the call to the generator.exe in the Xamarin Android folder (formatted for readability):

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\Android\generator.exe" ^
 obj\Debug\api.xml ^
 --codegen-target=XAJavaInterop1 ^
 --csdir=obj\Debug\generated\src ^
 --enumdir=obj\Debug\generated\enums ^
 --enummetadata=obj\Debug\generated\metadata ^
 --assembly=BrotherSDK.Android ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll" ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Java.Interop.dll" ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v9.0\Mono.Android.dll" ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll" ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll" ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Runtime.dll" ^
 --ref="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.dll" ^
 --fixup=Transforms\Metadata.xml ^
 --enumfields=Transforms\EnumFields.xml ^
 --enummethods=Transforms\EnumMethods.xml ^
 --api-level=28 ^
 --type-map-report=obj\Debug\generated\type-mapping.txt ^
 --global ^
 --public

When I run this command line in the project folder, I get (as expected) the same errors as in Visual Studio 2019. Now when I'm changing the path to generator.exe to use the VS 2017 generator.exe (but not changing the references to MonoAndroid assemblies), I get no warnings.

How can I fix these warnings? Or is this a regression in the generator.exe tool? Thanks!

jpobst commented 4 years ago

I'm not aware of anything that should have changed this in 16.4. Can you provide your api.xml so I can try to reproduce?

MFinkBK commented 4 years ago

Here's the api.xml from the obj/Debug folder. api.zip

jpobst commented 4 years ago

When you say Starting with VS 2019 16.4.0, what version were you on previously that works correctly? Are you jumping from VS2017 or were you on an earlier version of VS2019?

jpobst commented 4 years ago

I think this is caused by this change: https://github.com/xamarin/java.interop/pull/450.

We are attempting to resolve the type

System.Collections.Generic.IList<Java.Util.Locale.LanguageRange>

but the key in the symbol table is

System.Collections.Generic.IList`1

We need to either strip more arity or less.

Is this just a warning in your project? Does it actually keep any bindings from being generated?

MFinkBK commented 4 years ago

I was upgrading from VS 2019 16.3.10. It's just warning messages, but I try to be as warnings-free as possible. At the moment I have added a Jenkins console parse rule to not mark the messages as warnings.

MFinkBK commented 4 years ago

I see the commits in the master and the d16-5 branches. Is the fix contained in VS 2019 version 16.5.x then?

jpobst commented 4 years ago

Yes, it will be available beginning in 16.5 Preview 2.

awattar commented 4 years ago

What is the ETA of the 16.5 going stable?

For me this is critical as it broke my binding project due to chain of reactions that ending with whole types being removed from the generated binding.

BINDINGSGENERATOR : warning BG8800: Unknown parameter type System.Collections.Generic.ICollection<System.String> in method GetStringSet in managed type Android.Content.ISharedPreferences.
BINDINGSGENERATOR : warning BG8503: Invalidating Android.Content.ISharedPreferences and all nested types because some of its methods were invalid.
jpobst commented 4 years ago

I don't believe an RTM date has been announced for 16.5, however this fix is included in the 16.5 Preview 2 that came out this week. The preview installs side-by-side with your existing VS so you can use it without messing up your current VS.

https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview#16.5.0-pre.2.0

awattar commented 4 years ago

Unfortunately, I'm working on Mac and side by side preview doesn't work from some time.