Search Unity

[iOS] Include .dylib into build

Discussion in 'Scripting' started by RepoGames, Nov 19, 2017.

  1. RepoGames

    RepoGames

    Joined:
    Apr 15, 2016
    Posts:
    69
    Hello,
    I'm writing plugin using library https://github.com/libgit2/libgit2sharp
    They serve a couple of native .dll for windows/linux/iOS. Dynamic linking works for Windows/Linux using Plugin importer but it doesn't for iOS. The runtime is served under libgit2-15e1193.dylib file .

    I've tried to rename it to .bundle but it still says 'DllNotFoundException' on runtime.

    The libgit2sharp uses native library under the hood so as far as I understand I can't use syntax from https://docs.unity3d.com/Manual/NativePlugins.html like this:


    Code (CSharp):
    1.  #if UNITY_IPHONE
    2.  
    3.        // On iOS plugins are statically linked into
    4.        // the executable, so we have to use __Internal as the
    5.        // library name.
    6.        [DllImport ("__Internal")]
    7.  
    8.        #else
    9.  
    10.        // Other platforms load plugins dynamically, so pass the name
    11.        // of the plugin's dynamic library.
    12.        [DllImport ("PluginName")]
    13.  
    14.        #endif
    15.  
    16.        private static extern float FooPluginFunction ();
    as its only about this FooPluginFunction function, which I'm not accessing directly because libgit2sharp is doing that and I'm just using libgit2sharp API.

    How to include this file into the build?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    I've never reached directly into a native dylib from C# interop so I'm not sure if it is possible. I assume those endpoints require some apple-ish function call mechanism to get at, but I'm just speculating.

    I do know that it is possible to write a small ObjectiveC wrapper stub that maps the dylib's endpoints you want out to your own native C functions, and then you can call your C functions directly as that link above indicates, which would then hit your dylib endpoint(s).
     
  3. RepoGames

    RepoGames

    Joined:
    Apr 15, 2016
    Posts:
    69