Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

#import <Foundation/Foundation.h>

extern "C"
{
    void SampleFunction(); // this is going to call already bridged swift or objc code
}

sample.mm :

#import "Sample.h"
#import <SDK/SDKFunctions.h>

void SampleFunction()
{

    // my sweet functions calls

}

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

public class BundleImportSample : MonoBehaviour {


    #if UNITY_IOS
        [DllImport("__Internal")]
        private static extern void SampleFunction();
    #endif
        void Start()
        {
    #if UNITY_IOS
            SampleFunction();
    #endif
        }
    }

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 ?

like image 292
Greg Avatar asked Jun 22 '18 13:06

Greg


1 Answers

Code was fine.

The issue was about slices in the .bundle. It was built for i386 / x86_64 instead of arm64 / armv7 /armv7s.

To avoid this issue check the following options on your target :

  • Build on "Generic iOS device"
  • Build settings : "Build Active Architecture Only : NO"
  • Build settings : "Architecture : Standard architecture"
like image 126
Greg Avatar answered Sep 28 '22 17:09

Greg