Forum Xamarin.iOS

Unable to reference native framework

VictorNguyen1902VictorNguyen1902 USMember ✭✭
edited July 2020 in Xamarin.iOS

I followed all the instructions but cant seem to get this working.
I need to create bindings for Agora Video Call iOS Sdk.
Here's the steps I tried:

  1. Download the sdk and unzip: https://download.agora.io/sdk/release/Agora_Native_SDK_for_iOS_v3_0_1_1_FULL.zip?_ga=2.134487925.549327924.1594424861-931662975.1594424861
  2. Navigate to Agora_Native_SDK_for_iOS_FULL\libs\ALL_ARCHITECTURE
  3. Run sharpie command: sharpie bind -output Binding -framework ./AgoraRtcKit.framework -sdk iphoneos13.5
  4. Navigate to Binding and open ApiDefinitions.cs (about 2500 lines)
  5. Remove all the Verify tags.
  6. Create new iOS Binding library.
  7. Copy the content of Binding\ApiDefinitions.cs and Binding\StructsAndEnums.cs to ApiDefinition.cs and Structs.cs
  8. Add Native Reference -> select Agora_Native_SDK_for_iOS_FULL\libs\ALL_ARCHITECTURE\AgoraRtcKit.framework and click open.
  9. The compiler doesn't recognize 'AgoraRtcKit' even though it's been added.

I also tried unloading and reloading the project but that didn't help.

Am I missing something here?

Best Answer

  • VictorNguyen1902VictorNguyen1902 USMember ✭✭
    edited July 2020 Accepted Answer

    I feel stupid ... I figured this out after diving into the real details of sharpie and binding objective-c.
    Turns out whatever I did above is correct. It's just a matter of correcting the ApiDefinition.cs.

    Some stuffs/errors I came across that had to be modified:

    Remove unnecessary 'using AgoraRtcKit;' on top.
    void* -> IntPtr.
    Change delegate method name to reflect the preferred name if there exists another method with same parameters list. Ex:

    [Export("rtcEngine:didJoinChannel:withUid:elapsed:")]
    void RtcEngine(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    [Export("rtcEngine:didRejoinChannel:withUid:elapsed:")]
    void RtcEngine(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    // above changed to 
    [Export("rtcEngine:didJoinChannel:withUid:elapsed:")]
    void DidJoinChannel(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    [Export("rtcEngine:didRejoinChannel:withUid:elapsed:")]
    void DidRejoinChannel(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    

    Any type that seems too whacky or unsure, change to NSObject. The consumer can take care of the parsing/conversion.
    Namespace is important. Needs to be matched with the 'library' part of library.framework.
    Other minor translation between native and C#.

    Eventually was able to build and compile this ...

Answers

  • VictorNguyen1902VictorNguyen1902 USMember ✭✭
    edited July 2020 Accepted Answer

    I feel stupid ... I figured this out after diving into the real details of sharpie and binding objective-c.
    Turns out whatever I did above is correct. It's just a matter of correcting the ApiDefinition.cs.

    Some stuffs/errors I came across that had to be modified:

    Remove unnecessary 'using AgoraRtcKit;' on top.
    void* -> IntPtr.
    Change delegate method name to reflect the preferred name if there exists another method with same parameters list. Ex:

    [Export("rtcEngine:didJoinChannel:withUid:elapsed:")]
    void RtcEngine(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    [Export("rtcEngine:didRejoinChannel:withUid:elapsed:")]
    void RtcEngine(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    // above changed to 
    [Export("rtcEngine:didJoinChannel:withUid:elapsed:")]
    void DidJoinChannel(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    [Export("rtcEngine:didRejoinChannel:withUid:elapsed:")]
    void DidRejoinChannel(AgoraRtcEngineKit engine, string channel, nuint uid, nint elapsed);
    

    Any type that seems too whacky or unsure, change to NSObject. The consumer can take care of the parsing/conversion.
    Namespace is important. Needs to be matched with the 'library' part of library.framework.
    Other minor translation between native and C#.

    Eventually was able to build and compile this ...

  • jezhjezh Member, Xamarin Team Xamurai

    Congrats, and thanks for sharing the answer.

Sign In or Register to comment.