Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity iOS - Cannot import functions from .Bundle

Discussion in 'Editor & General Support' started by LeGweg, Jun 22, 2018.

  1. LeGweg

    LeGweg

    Joined:
    Jun 22, 2018
    Posts:
    3
    This post is also available on StackOverflow : https://stackoverflow.com/questions/50988617/unity-ios-cannot-import-functions-from-bundle

    Currently trying to create a wrapper for an iOS framework on Unity.

    I made a .bundle, containing basic objective-c code :

    sample.h :

    Code (CSharp):
    1. #import <Foundation/Foundation.h>
    2.  
    3. extern "C"
    4. {
    5.    void SampleFunction(); // this is going to call already bridged swift or objc code
    6. }
    sample.mm :

    Code (CSharp):
    1.  
    2. #import "Sample.h"
    3. #import <SDK/SDKFunctions.h>
    4.  
    5. void SampleFunction()
    6. {
    7.  
    8.    // my sweet functions calls
    9.  
    10. }
    11.  
    The SDK is included in the bundle as a .framework (references in "Linked Frameworks and libraries"). The bundle target is iOS.

    The bundle builds successfully.

    The bundle is placed in Unity under "Assets/Plugins/iOS", marked as "iOS" and "Add to Embedded Binaries"

    Then, in Unity, there is a simple C# script calling SDK functions :

    sample.cs

    Code (CSharp):
    1. #import <Foundation/Foundation.h>
    2.  
    3. extern "C"
    4. {
    5.    void SampleFunction(); // this is going to call already bridged swift or objc code
    6. }
    When I test this code in the editor I get the following error :

    EntryPointNotFoundException: SampleFunction

    If I build the generated project on iOS, I get a similar issue :

    ld: symbol(s) not found for architecture arm64

    Note : I used the following tutorial as guideline : http://blog.mousta.ch/post/140780061168

    Why is SampleFunction() not found in __Internal ?
     
    Last edited: Jun 22, 2018
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Did you do all the steps including the expose as module as well as building a universal bundle instead of armv7 / arm64 only? otherwise a Unity universal build with both arch would fail.

    also when you dropped the bundle into unity did you ensure that the platform is configured correctly (iOS and editor enabled and project set to iOS); this also includes that the public static extern methods with dllimport that you define need to be in #if UNITY_IOS - I'm asking because I've seen cases where bundles were dropped into project and caused failures in the osx editor because either the #if and/or the platforms were incorrect.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you can test if your c# side is fine by dropping the h and mm files into unity itself, setting platforms and if necessary dependencies (for some you might need a post build step using the pbx project class in unityeditor.ios to update the xcode project with them - all the.a libs for example)
     
  4. LeGweg

    LeGweg

    Joined:
    Jun 22, 2018
    Posts:
    3
    Solved ! The bundle was targeting universal devices / standard architectures; the expected slices were arm64, armv7 and armv7s.
    But the build was done with a "simulated device" (Iphone 8) instead of "Generic iOS device", resulting in a product sliced in i386 and x86_64 -> the bundle was not supporting architecture arm64.

    Thanks @Dreamora !