xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.44k stars 505 forks source link

Build fails with "no type or protocol named 'MTKViewDelegate'" after adding mtouch argument --registrar:static #4422

Closed TobiasBuchholz closed 6 years ago

TobiasBuchholz commented 6 years ago

Steps to Reproduce

  1. I'm trying to add the mtouch argument --registrar:static to my native iOS xamarin project but it results in the build errors from below. I would like to add the argument because it solves another build error after I've added the Xamarin.Firebase.iOS.Analytics nuget package to the project. The build is only failing for the simulator, builds for devices are fine.

Expected Behavior

The build succeeds without any problems.

Actual Behavior

The build fails with errors like

/Users/tobiasbuchholz/Work/PressMatrix/xamarin/PressMatrix/PressMatrix.UI.iOS/obj/iPhoneSimulator/Debug/mtouch-cache/registrar.h(6579,53): error G9EBEE159: no type or protocol named 'MTKViewDelegate'
    @interface MetalKit_Rx_MTKViewDelegateRx : NSObject<MTKViewDelegate> {
                                                        ^ 
/Users/tobiasbuchholz/Work/PressMatrix/xamarin/PressMatrix/PressMatrix.UI.iOS/obj/iPhoneSimulator/Debug/mtouch-cache/registrar.h(6585,25): error G5EC502AB: expected a type
    -(void) drawInMTKView:(MTKView *)p0;
                                   ^ 
/Users/tobiasbuchholz/Work/PressMatrix/xamarin/PressMatrix/PressMatrix.UI.iOS/obj/iPhoneSimulator/Debug/mtouch-cache/registrar.h(6586,19): error G5EC502AB: expected a type
    -(void) mtkView:(MTKView *)p0 drawableSizeWillChange:(CGSize)p1;
                             ^ 
/Users/tobiasbuchholz/Work/PressMatrix/xamarin/PressMatrix/PressMatrix.UI.iOS/obj/iPhoneSimulator/Debug/mtouch-cache/registrar.m(27402,99): error GC871EEFB: unknown type name 'MTKView'
    static void native_to_managed_trampoline_494 (id self, SEL _cmd, MonoMethod **managed_method_ptr, MTKView * p0, uint32_t token_ref)
                                                                                                      ^ 
/Users/tobiasbuchholz/Work/PressMatrix/xamarin/PressMatrix/PressMatrix.UI.iOS/obj/iPhoneSimulator/Debug/mtouch-cache/registrar.m(27449,99): error GC871EEFB: unknown type name 'MTKView'
    static void native_to_managed_trampoline_495 (id self, SEL _cmd, MonoMethod **managed_method_ptr, MTKView * p0, CGSize p1, uint32_t token_ref)

Environment

=== Visual Studio Community 2017 for Mac ===

Version 7.5.3 (build 7)
Installation UUID: d36b125f-2ca5-46ea-b457-c9cb84803a65
Runtime:
    Mono 5.10.1.57 (2017-12/ea8a24b1bbf) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

    Package version: 510010057

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.1
    2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.301/Sdks
SDK Versions:
    2.1.301
    2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 8.3.3.2 (Visual Studio Community)
Android SDK: /Users/tobiasbuchholz/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        4.4 (API level 19)
        6.0 (API level 23)
        7.0 (API level 24)
        7.1 (API level 25)
        8.0 (API level 26)
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 28.0.0 rc2

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1

=== Apple Developer Tools ===

Xcode 9.4.1 (14161)
Build 9F2000

=== Xamarin.Mac ===

Version: 4.4.1.193 (Visual Studio Community)

=== Xamarin.iOS ===

Version: 11.12.0.4 (Visual Studio Community)
Hash: 64fece5f
Branch: d15-7
Build date: 2018-05-29 20:00:44-0400

=== Build Information ===

Release ID: 705030007
Git revision: 13cecd02aceddf29a1ed57b86f81c02994df1483
Build date: 2018-06-14 15:48:08-04
Xamarin addins: 7065de97cf22c9038fdc39dd627f2c30790fd8af
Build lane: monodevelop-lion-d15-7

=== Operating System ===

Mac OS X 10.13.3
Darwin 17.4.0 Darwin Kernel Version 17.4.0
    Sun Dec 17 09:19:54 PST 2017
    root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Redth's Addins 1.0.9
Internet of Things (IoT) development (Preview) 7.5

Build Logs

Build Logs Gist

Example Project (If Possible)

Since the project is for work I can't share it unfortunately. I've tried to create a sample project with the same packages but for this project the build succeeds without any problems.

mandel-macaque commented 6 years ago

Hello,

That is unexpected. Since you cannot send the project, could you send your register.h and .m so we can see what the problem is. It might be the case that some headers are missing in the sim or something similar.

TobiasBuchholz commented 6 years ago

Sure, here you go: registrar.zip

rolfbjarne commented 6 years ago

It looks like we're not detecting MetalKit usage properly, and thus not adding the proper include directive in the generated registrar code.

@TobiasBuchholz can you try manually using a MetalKit type in your project, by adding something like this as the last line of your Main method:

Console.WriteLine (typeof (MetalKit.MTKView));

hopefully this will make us detect that MetalKit is used, and thus add the corresponding include directive in the generated code.

TobiasBuchholz commented 6 years ago

Hi, I've put that line as last line into my Application.Main(string[] args) method, but that didn't seem to change anything unfortunately.

Build Logs

rolfbjarne commented 6 years ago

Actually this looks like we're skipping MetalKit on purpose for simulator builds, because at first Apple didn't ship the MetalKit framework for the simulator (it would only work for device builds).

I'll have a look to see if this is still the case, but you may be able to work around it by enabling the linker (in the iOS Build options, change Linker Behavior for simulator builds to match the value for device builds). This might link away all the code that references MetalKit, and thus hopefully the generated registrar code won't need it anymore.

If that doesn't work, the last solution would be to add a conditional compilation symbol for simulator builds, and use it to conditionally exclude all MetalKit related code (you seem to have a MTKViewDelegateRx class: I'd start here)

TobiasBuchholz commented 6 years ago

Unfortunately changing the linker behavior doesn't work either.

But thanks to your hint I was able to pin down the problem to the package ReactiveUI.Events. It's an optional part of the MVVM framework ReactiveUI, which looks at all the EventHandlers for a platform and generates Observable.FromEventPattern extension methods, so this is why MetalKit gets included but it's also why I can't apply your conditional compilation symbol trick.

So I guess I'll either have to remove this package (which would be a shame, because it's quite useful) or I'll have to create an issue on their github page, right?

Thanks anyways :)

rolfbjarne commented 6 years ago

So I guess I'll either have to remove this package

You could still conditionally exclude all the code that uses that assembly/package from simulator builds.

Assemblies that are not needed at all are not added to the app.

I'll have to create an issue on their github page, right?

I don't think this is their bug, at least until we've confirmed if we can fix this on our side or not.