-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS Binding Does Nothing #14775
Comments
A few things:
I pulled down my repo that you listed, built it with no errors and it worked fine when I referenced the output in another project. The only other thing I can think of is that you can't directly reference binding projects with other projects. If you're trying to, for example, reference a binding project with your MAUI app, that won't work. You would need to reference the output DLLs of the binding (or create a Nuget package and reference that) and then it should work. @rolfbjarne Am I correct? Does this sound right? |
You can reference a binding project from another project, it'll kind of work. The IDE will tell you that there's a problem (red squiggly lines when trying to use anything from the binding project), but if you try to build, it'll build just fine (this is a known issue). That said, just referencing the output dll makes the IDE happy as well, so most people do that. Otherwise everything else is correct. |
Thanks for the responses guys! @drasticactions I do not get any errors at all when I compile. I added those namespaces and still get no errors, infact, I can absolutely trash the entire ApiDefinition file with random errors and changes and it still claims to compile fine. What version of VS are you using and the dot net version installed? (I have listed mine at the bottom of this comment). Also thankyou for pointing out the XMGreeting enum, that is suppose to be in the StructsAndEnums class. But that is also a perfect example of the project compiling without any problems when clearly it should be failing to compile. Do note that if I create a Xamarin Binding project, it will compile and I can then reference the xamarin DLL in a xamarin project. To verify this is not a problem on just my computer. I have just done a fresh install of Visual Studio 2022 community on a laptop, and I get the exact same behaviour. The installed version I am running on both computers is:
|
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
Thanks for the issue report @Tazzi3! This issue appears to be a problem with Visual Studio, so we ask that you use the VS feedback tool to report the issue. That way it will get to the routed to the team that owns this experience in VS. If you encounter a problem with Visual Studio, we want to know about it so that we can diagnose and fix it. By using the Report a Problem tool, you can collect detailed information about the problem, and send it to Microsoft with just a few button clicks.
|
I'm doing this on my Mac, I haven't tried to build and reference a Binding project on Windows. In any case, this issue wouldn't be one for this Repo: It's unrelated to the MAUI UI Framework. This sounds like a tooling issue on Windows, so I would file an issue there and see. |
Ah, I didn't notice that this happens on Windows. At the moment, building a binding project on Windows requires having a connection to a remote Mac (see also xamarin/xamarin-macios#16244). |
I will try again on the MAC and report back! |
@drasticactions @rolfbjarne We have had success with compiling in MAC Visual Studio. I can then confirm that the desired functions are displaying in the DLL when decompiling it. When I copy the DLL over to Windows Visual Studio and attempt to use it in a MAUI application, I get the following error: When looking at the Microsoft.iOS version in my MAC visual studio, it shows it is using Microsoft.iOS v16.2.46 Is it possible to manually update the version? Or can I copy the DLL from the windows version onto the MAC to make them the same? |
Can you get a binary build log (binlog) as described here: https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#binary-build-logs? |
Yes I can get that today. But I am getting the same issue as this person: xamarin/xamarin-macios#17418 The Microsoft.iOS SDK used between MAC and Windows Visual Studio is different. I have tried completely uninstalling and reinstalling Visual Studio 22 on both machines at the same time and they still use two different versions. I can see there are newer versions of the SDK which can be seen on the nuget link: https://www.nuget.org/packages/Microsoft.iOS.Windows.Sdk/ But trying to install these results in the same error that the previous person got which was: I did try a variety of different versions as well, but the v16.2.46 is the version that matches the MAC VS install. |
Marking as need info: #14775 (comment) |
Hi @Tazzi3. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. |
Same issue, iOS binding api definition not working. Android binding just copy jar frome Xamarin Android binding will be success, AndroidBinding project compile success, and add it to Android maui project ( In iOS binding, copy all .a files and ApiDefinition.cs/StructsAndEnums.cs files, the iOSBinding project can compile success, but add it to iOS maui project ( Add .a/.framework to iOSBinding project is like the following:
|
There's a known issue where intellisense in the IDE won't work, but the build will actually succeed. Can you try building the project and see if that works? One workaround is to reference the binding assembly directly instead of the binding project, in which case intellisense will work as expected. |
Thanks, it build success and work correctly with wrong intellisense. The test lib files and define are these: #ifndef TestiOS_h
#define TestiOS_h
#import <Foundation/Foundation.h>
@interface TestiOS : NSObject
- (int) add:(int)a b:(int)b;
@end
#endif /* TestiOS_h */ TestiOS.m #import "TestiOS.h"
@implementation TestiOS
- (int) add:(int)a b:(int)b {
return a+b;
}
@end ApiDefinition.cs <-- Create from sharpie using Foundation;
namespace BindingiOS
{
// @interface TestiOS : NSObject
[BaseType(typeof(NSObject))]
interface TestiOS
{
// -(int)add:(int)a b:(int)b;
[Export("add:b:")]
int Add(int a, int b);
}
} Test code in Program.cs BindingiOS.TestiOS testobj = new BindingiOS.TestiOS();
int a = 15;
int b = 57;
int c = testobj.Add(a, b); |
Can you show your csproj file? |
Hi @Tazzi3. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version. You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Verified this issue with Visual Studio Enterprise 17.9.0 Preview 3 and VSMac 17.6.8.400. Builds without errors using user-provided projects. And when I try to reference a binding project from another project, it still works fine. |
Description
I can successfully get an iOS Objective-C library (.a file) to bind following the Xamarin binding tutorial found here: https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/binding/objective-c-libraries.
I also used the library that the tutorial recommended to follow which is located here: https://github.com/xamarin/ios-samples/tree/master/BindingSample
Now I am trying to do the same for MAUI. When selecting a MAUI iOS binding library, adding the ios static library, and copying in the same code, it says it compiled but it has not actually done anything. The dll produced has no functions present when decompiling and checking it. Its almost like VS does not recognize that it is a binding library setup and basically does nothing.
Things I have tried for a fix:
Am I missing something critical for MAUI template to work in comparison to how XAMARIN does it?
Steps to Reproduce
Link to public reproduction project repository
https://github.com/Tazzi3/MAUI-ObjC-Binding
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
all iOS
Did you find any workaround?
No work around.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: