jiulongw / swift-unity

Sample code that integrate Unity (2017.1+) scene into iOS (Swift 4.0, Xcode 9+) project.
390 stars 100 forks source link

Running Unity 2018.3 + Vuforia 8 + Xcode 10 #125

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi. I want to make this tutorial of how I was able to run Unity 2018.3 + Vuforia 8 + Xcode 10. So, let's get started!

Configure

  1. Create a new Swift proyect and save it wherever you want
  2. Create a new Unity+Vuforia proyect and make your AR scene as usual

Unity Proyect: When you are ready to export your Unity+Vuforia proyect, continue with this configuration:

  1. Add the file XcodePostBuild.cs and configure the routes (follow the project tutorial if you don't know how to edit this file)
  2. Go to Players settings -> other settings and: 3.1 Uncheck Auto Graphics API 3.2 Add OpenGLES2 in Graphics API 3.3 Remove Metal in the same list menu 3.4 Uncheck Metal Editor Support 3.5 For Scripting Runtime Version I'll be using .NET 4.x Equivalent 3.6 Architecture must be Universal 3.7 Uncheck Strip Engine Code
  3. Export your Unity-Xcode project wherever you want

Swift Project: When your Unity-Xcode project finish, go back to your Swift application. We'll be following the same steps of the swift-unity tutorial...

  1. Copy entire Unity folder to the root of your Swift project to link it with the options "Copy items if needed" and "Create groups" checked.
  2. Copy and paste the "Classes" and "Libraries" folders from the Unity export folder into the Xcode project into the previous Unity folder created, using the options "Copy items if needed" and "Create groups" checked.
  3. Copy the "Data" folder into Xcode but, only with the “Create folder references” option.
  4. Copy the "Vuforia" folder into Xcode using the options "Copy items if needed" and "Create folder references" checked. This folder can be found in your Unity-Xcode route your_unity_project/data/raw/Vuforia

At this moment, you must have this structure: Captura de pantalla 2019-03-15 a la(s) 1 27 18

Note: If you don't see Exports.xcconfig file inside the Unity Folder, is already there... only add the reference to the file.

As I said before, I'll be using .Net 4.x so:

  1. Open the Unity.xcconfig file and append _-DNET_40 to _OTHERCFLAGS
  2. Go in the General tab of the project and set the “Unity” configuration profile
  3. Remove references of this files (Unity/Classes): 7.1 DynamicLibEngineAPI-functions.h 7.2 DynamicLibEngineAPI.mm
  4. Go to the file in Unity/Classes/UI/SplashScreen.mm and change the line: #include "Classes/Unity/UnitySharedDecls.h" with: #include "../Classes/Unity/UnitySharedDecls.h"
  5. Go to the file in Unity/Classes/Unity/DeviceSettings.mm and add: return deviceUnknown; between the lines 280-281 (after the #endif and } )
  6. Go to your Target settings, in the section General->Embeded Binaries click on the + icon and Add other.... Navigate back to the Unity-Xcode proyect and look for the Vuforia.framework inside the root folder Frameworks. When selected, set the options "Copy items if needed" and "Create folder references" checked.
  7. Go back to your Target settings and add AVKit.framework in section General->Linked frameworks and libraries

Now, your target settings must look as this: Captura de pantalla 2019-03-15 a la(s) 1 46 27

If you followed this tutorial, now you'll be able to compile the swift project without errors. To display the Unity-Vuforia, just continue following the swift-unity tutorial... Update the AppDelegate.swift, set up your Controllers and/or Storyboards, set the camera policy in your info.plist... and that's it!

Thank you so much for taking your reading this tutorial. I hope to be able to help you :)

carlgik4 commented 5 years ago

There is a small issue need to fix, we need to set Enable Testability to No.

As we use Xcode 10, the default project capability is "Xcode 9.3 compatible", and the "objectVersion = 50;" in pbxproj file. as you leave these new settings, you may encounter build error:

:-1: Undefined symbol: _mono_log_open_asl
:-1: Undefined symbol: _mono_log_write_asl
:-1: Undefined symbol: _mono_log_close_asl

If you compare with the same item of older project "LD xxx/Debug-iphoneos/Play.build/Objects-normal/arm64/Play normal arm64 (in target: Play)"

you will find an extra xlinker "-Xlinker -export_dynamic", which will make the building process failed. But if we change Enable Testability to No, that error will be fixed.