2

I created a binding project for Xamarin iOS. I succeeded in adding the native library, creating the C# Bindings and resolved all the hundreds of errors I found just to get this error once I try to run the library (in an app on the iPhone simulator):

Could not create a native instance of the type 'MyNamespace.STPPaymentCardTextField': the native class hasn't been loaded.

Here is the signature of the interface in objective-c:

@interface STPPaymentCardTextField : UIControl <UIKeyInput>

Here is what I get in my C# iOS binding:

[BaseType(typeof(UIControl))]
[Protocol]
interface STPPaymentCardTextField : IUIKeyInput

I read this stackoverflow answer and checked the architecture for which my library was built and here is the architecture, taking into consideration that I run it on the iOS simulator:

are: i386 x86_64

here is the script I use to build the library:

all: lib$(TARGET).a

lib$(TARGET)-i386.a:
  $(XBUILD) -project $(PROJECT) -target $(TARGET) -sdk iphonesimulator -configuration Release 
clean build
 -mv $(PROJECT_ROOT)/build/Release-iphonesimulator/lib$(TARGET).a $@


lib$(TARGET).a: lib$(TARGET)-i386.a 
  xcrun -sdk iphoneos lipo -create -output $@ $^

clean:
  -rm -f *.a *.dll

How can I resolve this error please ?

John Code
  • 655
  • 7
  • 24
  • Hi , do you use `assembly` to load `.a` file in project ,such as : `[assembly: LinkWith ("xxx.a", SmartLink = true, ForceLoad = true)]` ? – Junior Jiang May 29 '20 at 03:04
  • Hello, no I don't do that where should I do that ? – John Code May 29 '20 at 07:05
  • Okey , you can have a look at here : https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/binding/objective-c-libraries – Junior Jiang May 29 '20 at 07:12
  • Hi @JuniorJiang-MSFT thanks I went through the docs and I added the file with these two lines only: using ObjCRuntime; [assembly: LinkWith("libStripe.a", LinkTarget.ArmV7 | LinkTarget.Simulator| LinkTarget.Arm64, SmartLink = true, ForceLoad = true, Frameworks = "")] – John Code May 29 '20 at 09:26
  • But after doing that, I had false error messages appearing, the errors are of this type: https://learn.microsoft.com/en-us/xamarin/ios/troubleshooting/mtouch-errors#MT5211. Telling me the [Protocol] is miising on some classes whereas it is there in the code and I reference the dll is up to date. – John Code May 29 '20 at 09:29
  • And another error message which appeared this message of the type: https://learn.microsoft.com/en-us/xamarin/ios/troubleshooting/mtouch-errors#MT5210 The library I'm building depends on several frameworks, one of which is of type "framework.a" but the docs do not precise how to add external frameworks or even how to add more than one framework, I'm kind of missing something please could you help ? – John Code May 29 '20 at 09:34
  • Okey , I will check that . Due to time to leave my office , if good idea will update here later :-) – Junior Jiang May 29 '20 at 09:56
  • Hello @JuniorJiang-MSFT any info about how to resolve this please ? – John Code Jun 01 '20 at 10:48
  • Hi , whether serveral frameworks call each other ,and the type of them whehter all are `xxx.a` ? – Junior Jiang Jun 02 '20 at 01:26
  • I mean, the library I'm trying to bind has dependecies on several other frameworks and one of these frameworks is another static library "lib.a" do you know how to add them to the iOS binding ? the docs show only how to add one. – John Code Jun 02 '20 at 08:26
  • How about [Linking the dependencies](https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/binding/objective-c-libraries#linking-the-dependencies) works for you ? – Junior Jiang Jun 02 '20 at 08:42

1 Answers1

0

Can you make sure you have "UIKit" listed under frameworks. "Native references ->"properties of native library" -> "frameworks: UIKit"