I exported Unity app as framework successfully, then include it as framework to use by another application.
It’s very similar and I think it’s the same approach as Yao2ich tried to do here.
I changed [NSBundle mainBundle] as seen across the source files in exported XCode project to [NSBundle bundleForClass:[UnityRenderingView class]] as to just make sure it refer to the correct bundle, it’s not main bundle anymore.
Then finally after properly configured build settings linked against libraries, and built. Crash occurs at
UnityInitApplicationNoGraphics([[[NSBundlebundleForClass:[UnityRenderingViewclass]] bundlePath] UTF8String]); inside UnityAppController.mm file. See attached screenshot for more information.
My system is macOS Sierra 10.12 (16A294a), Xcode 7.3.1 (7D1014), and Unity 5.4.0f3.
Note:
Even though if I didn’t change [NSBundle mainBundle] code but made sure Data folder is copied to the main bundle, I still got the exact same error. So in this case I think that this NSBundle stuff should not effect the issue I’m facing.
I suspect it might be about write protection, but what I did is neither trying to modify its resource (Data/) or bypassing launch screen. But really not sure what’s the matter with WriteLock() problem as seen in the attached screenshot above.
It seems like it will be okay only if I build the project with default set up of exported project from Unity. If I tried to link against framework (turned into framework from Unity app) then it gave above error.
It’s not possible at the time being @cyberIndia .
I’ve pushed effort in turning the Unity-based project into framework and static library. Both didn’t work out, although the latter came very close to result I want to achieve.
I even submitted as a bug report to Unity, but Unity support replied me back that that feature is not supported. I think if more and more people want to do what we do, then they might look into it later.
@haxpor
They are saying that Including Unity app in a native is not possible, but I have already done it. I am able to run a Unity Project inside a Native iOS project. I was looking to make it in a distributable form. I want to make a framework that i can give to my clients so they can use it to import my unity app in their native apps…
Hey guys, I think be careful about the wording. The point for this is to make Unity project as a framework to be imported by 3rd party native app.
@cyberIndia said you can embed Unity inside the native app. Can you confirm? Because at the end it’s Unity app that wraps around native app. The build process need Unity app to be the wrapper, to control native app. I believe I achieved the same thing as you, but cannot make it as framework the same.
One thing to notice for difference, if you still need to hand the whole Unity project for someone to integrate , this means it’s embedding native into Unity which is possible.
@cyberIndia please confirm for all of us if you can achieve that? I’d love to know too. Thanks!
I am also facing this WriteLock() crash and was wondering if anyone has been able to resolve it? If I integrate the Unity build to the native host app manually, everything works just fine. But when I add it as a cocoa touch framework, it crashes like this. I also have the framework as a dynamic library.
I have the Data/ directory included in both HostApp.app/ and HostApp.app/Frameworks/UnityBuild.framework/Data/ but that makes no difference. Could this crash be related to some file being within the HostApp.app/Frameworks/UnityBuild.framework/ instead of the HostApp.app/ directory or about the write protection of those files? (UnityBuild.framework is the framework I built from the Unity generated files)
Anyone from Unity that could have a clue why this is happening? I know that building this kind of framework is not supported by Unity but any help would be appreciated.
Hi @haxpor @Ed_bt@Makro , how you build Unity as a cocoa touch framework successfully?
I’m try to created a new target, add unity code to the target. but there lots of build errors. I have no clue how to resolve it.
@forest_linshs I did it like that. I had a single view project that I added the Unity build manually to so that I could open Unity from a button. Lots of resources on the web for doing that. Then I added a new build target for the framework and moved the Classes/ and Libraries/ folders to it. Then I just fixed the build errors as they came and linked the built framework to the original build target. If you’re having trouble with some errors, try to search for the specific error you’re having and see if you can find a solution.
Hi @haxpor , could you tell me how I can export ios build as a framework?
I’m trying to step into including unity into ios app, but no luck in terms of guidance.
I’ve done this the other way around. I integrated an iOS project into a Unity project. So Unity is used as the bootstrap, and you can switch to an iOS native view (which will suspend Unity) and then switch back to Unity whenever you want.