blitzagency/ios-unity5

xcode9 and unity 2017.1

Opened this issue · 16 comments

etown commented

has anybody had success? I was able to get it to build what it would crash consistently on startup.

Yeah, you need to put @objc in front of var currentUnityController: UnityAppController! in AppDelegate.swift. This is because of Swift 4.0. You can see the previous thread with a link.

etown commented

thanks, but this issue I am having is a crash on startup:
UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]);
Thread 1: EXC_BAD_ACCESS (code=1, address=0xb8)

Anyone else having the same issue?

etown commented

@etown Change UnityInitApplicationNoGraphics([[[NSBundle mainBundle] bundlePath] UTF8String]); to

NSBundle *bundle = [NSBundle bundleForClass:[self class]];
UnityInitApplicationNoGraphics([[bundle bundlePath] UTF8String]);
etown commented

@mrniket thanks! I tried your suggested change, but still a crash at startup:
screen shot 2017-09-11 at 3 20 45 pm

did you have to make any other changes from the 5.x method? thanks!

Hi @etown, sorry for the late reply! I also changed this line in Unity.xcconfig:
OTHER_CFLAGS = -DINIT_SCRIPTING_BACKEND=1;
to:
OTHER_CFLAGS = $(inherited) -DINIT_SCRIPTING_BACKEND=1 -fno-strict-overflow -DRUNTIME_IL2CPP=1;

Does that work for you?

Hey, @mrniket.

I'm on the same issue and sadly, the second suggestion didn't help too.

We were having problems like this in our project so I made two scripts to try and automate this stuff.

Given you have:

  • updated your OTHER_CFLAGS in .xcconfig to
    OTHER_CFLAGS = $(inherited) -DINIT_SCRIPTING_BACKEND=1 -fno-strict-overflow -DRUNTIME_IL2CPP=1;
  • added the @objc in front of var currentUnityController: UnityAppController!

you should be able to use these scripts if you just change the paths to whatever they are in your project. The fixProjectFile.rb script tries to set up the file references correctly in your Xcode project file. The projectRefresh.rb script performs the file changes you need to do every time you build from Unity.

https://github.com/ocadotechnology/rapid-router-ios/blob/blockly_translator/fixProjectFile.rb
https://github.com/ocadotechnology/rapid-router-ios/blob/blockly_translator/projectRefresh.rb

Hopefully these work for you!

etown commented

@mrniket thank you, it works!

I'm using Unity 5.6.2f1 with success on Xcode 9. But with 2017.1.1f1 if I build and insert my project on Xcode 9, I have linker-o symbol not found error. Anybody try to build with Unity 2017.1.1f1 with success ?

Plus any idea on how to support plugin in embedded unity app ? I'm trying to use GVRSDK on unity, build project and embed in my native iOS app but can't build it on Xcode...

@jplongo Here is a complete demo project that embed Unity 2017.1.1f1 into Xcode 9 Swift project: https://github.com/jiulongw/swift-unity

You didn't post error details so I can only guess your issue.

  1. Some generated .h/.mm files are moved around so you need to update header search path a bit. Especially, add $(UNITY_IOS_EXPORT_PATH)/Classes/Unity
  2. Xcode 9 seems to have a bug that if you drag-n-drop a folder into Xcode project tree and create group, regardless you choose to add files to build target or not, the .mm files are not added to build target. A work around is to right click Xcode project tree and select add files from there.
  3. Remember to add the bridging header file to build settings. Otherwise things like unity_init is not available in Swift.

As for GVRSDK, as long as you add folder containing .a to library search path and link the library (e.g. -lgvr if the file name is libgvr.a), I don't see any reason why it cannot be build in Xcode.

Hi all ,
i am also facing the same crash and did all above but still app is crashing i am using xcode 9.4 and 2017.3.1f1 Unity version

i have updated this :-


updated your OTHER_CFLAGS in .xcconfig to
OTHER_CFLAGS = $(inherited) -DINIT_SCRIPTING_BACKEND=1 -fno-strict-overflow -DRUNTIME_IL2CPP=1;
added the @objc in front of var currentUnityController: UnityAppController!


but unble to implement these step can any one help me to implement these .rb files

you should be able to use these scripts if you just change the paths to whatever they are in your project. The fixProjectFile.rb script tries to set up the file references correctly in your Xcode project file. The projectRefresh.rb script performs the file changes you need to do every time you build from Unity.

https://github.com/ocadotechnology/rapid-router-ios/blob/blockly_translator/fixProjectFile.rb
https://github.com/ocadotechnology/rapid-router-ios/blob/blockly_translator/projectRefresh.rb


NSBundle *bundle = [NSBundle bundleForClass:[self class]];
UnityInitApplicationNoGraphics([[bundle bundlePath] UTF8String]);
(For Xcode 10.2 and Unity 2019)
This solution is also not working getting UnityInitApplicationNoGraphics EXE_BAD_ACCESS

I got it working on Xcode version 10.2.1 (10E1001) + Unity 2018.2.18f1 by changing:

Unity/Classes/CrashReporter.h from:

#pragma once

// Enabling this will force app to do a hard crash instead of a nice exit when UnhandledException
// is thrown. This will force iOS to generate a standard crash report, that can be submitted to
// iTunes by app users and inspected by developers.
#define ENABLE_IOS_CRASH_REPORTING 1

// Enabling this will add a custom Objective-C Uncaught Exception handler, which will print out
// exception information to console.
#define ENABLE_OBJC_UNCAUGHT_EXCEPTION_HANDLER 1

// Enable custom crash reporter to capture crashes. Crash logs will be available to scripts via
// CrashReport API.
#define ENABLE_CUSTOM_CRASH_REPORTER 1

// Enable submission of custom crash reports to Unity servers. This will enable custom crash
// reporter.
#define ENABLE_CRASH_REPORT_SUBMISSION 1


#if ENABLE_CRASH_REPORT_SUBMISSION && !ENABLE_CUSTOM_CRASH_REPORTER
    #undef ENABLE_CUSTOM_CRASH_REPORTER
#define ENABLE_CUSTOM_CRASH_REPORTER 1
#endif

#if PLATFORM_TVOS
    #undef ENABLE_CUSTOM_CRASH_REPORTER
#define ENABLE_CUSTOM_CRASH_REPORTER 1
#endif


void WaitWhileCrashReportsAreSent();
void SubmitCrashReportsAsync();
void UnityInstallPostCrashCallback();
void InitCrashHandling();

to:

#pragma once

// Enabling this will force app to do a hard crash instead of a nice exit when UnhandledException
// is thrown. This will force iOS to generate a standard crash report, that can be submitted to
// iTunes by app users and inspected by developers.
#define ENABLE_IOS_CRASH_REPORTING 0

// Enabling this will add a custom Objective-C Uncaught Exception handler, which will print out
// exception information to console.
#define ENABLE_OBJC_UNCAUGHT_EXCEPTION_HANDLER 0

// Enable custom crash reporter to capture crashes. Crash logs will be available to scripts via
// CrashReport API.
#define ENABLE_CUSTOM_CRASH_REPORTER 0

// Enable submission of custom crash reports to Unity servers. This will enable custom crash
// reporter.
#define ENABLE_CRASH_REPORT_SUBMISSION 0


#if ENABLE_CRASH_REPORT_SUBMISSION && !ENABLE_CUSTOM_CRASH_REPORTER
    #undef ENABLE_CUSTOM_CRASH_REPORTER
#define ENABLE_CUSTOM_CRASH_REPORTER 0
#endif

#if PLATFORM_TVOS
    #undef ENABLE_CUSTOM_CRASH_REPORTER
#define ENABLE_CUSTOM_CRASH_REPORTER 0
#endif


void WaitWhileCrashReportsAreSent();
void SubmitCrashReportsAsync();
void UnityInstallPostCrashCallback();
void InitCrashHandling();

@ZombieMK :I tried above solution but still getting below error at line UnityInitApplicationNoGraphics([[bundle bundlePath] UTF8String]);

Error :Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

Console Output is :2019-04-23 08:28:24.984534+0530 ProjectName[9685:153486] libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.
2019-04-23 08:28:24.985 ProjectName[9685:153486] Built from '2019.1/staging' branch, Version '2019.1.0f2 (292b93d75a2c)', Build type 'Development', Scripting Backend 'il2cpp'
2019-04-23 08:28:25.014076+0530 ProjectName[9685:153486] -> registered mono modules 0x10aa6c1e8
-> applicationDidFinishLaunching()
Could not load symbol il2cpp_init : (null)

(Filename: ./Runtime/Modules/LoadDylib.cpp Line: 199)........

I encountered same problem and didn't get resolved with above solution, but I find the old project has some strange flags in other c++ flags(OTHER_CPLUSPLUSFLAGS): -x objective-c++, which cause the runtime crash for unity, after remove these flags, and do some minor changes for source code, it works!