Search Unity

Build Unity app as framework then consumed by another app

Discussion in 'iOS and tvOS' started by haxpor, Sep 8, 2016.

  1. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    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
    Code (CSharp):
    1. [NSBundle mainBundle]
    as seen across the source files in exported XCode project to
    Code (CSharp):
    1. [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

    Code (CSharp):
    1. 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
    Code (CSharp):
    1. [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.
     

    Attached Files:

  2. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    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.
     
  3. cyberIndia

    cyberIndia

    Joined:
    Aug 17, 2014
    Posts:
    8
    Hi

    I am also working on something (exactly) like this... Doing the internet research tells me its kinda not possible. Has anyone ever accomplished this?

    What is the progress on your side?

    I'll also post, if i make any achievement in this direction...

    Regards

    Dipender Kaushik
     
  4. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    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.

     
  5. cyberIndia

    cyberIndia

    Joined:
    Aug 17, 2014
    Posts:
    8
    @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...
     
    Last edited: Oct 20, 2016
  6. cj657206427

    cj657206427

    Joined:
    Oct 20, 2016
    Posts:
    4
    @cyberIndia I also want to make a framework,what's your solution?
     
  7. thedanielfactor_unity

    thedanielfactor_unity

    Joined:
    Oct 26, 2016
    Posts:
    1
    I would like to do this also. @cyberIndia . What is your solution.
     
  8. Ed_bt

    Ed_bt

    Joined:
    Oct 1, 2012
    Posts:
    19
    Anyone can point in the right direction on how to export unity as a framework? Just thow the exported ios on a cocoa touch framework? Tks in advance
     
  9. haxpor

    haxpor

    Joined:
    Oct 15, 2012
    Posts:
    11
    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!
     
  10. Ed_bt

    Ed_bt

    Joined:
    Oct 1, 2012
    Posts:
    19
    Yes you can bundle unity inside a Native app. I have done it and there are some tutorials on the web that show you how to do it.
     
  11. dingxiuweiUnity

    dingxiuweiUnity

    Joined:
    Dec 27, 2016
    Posts:
    5
    i have the same problem。But why? one is library dependency ,the other is source code dependency!
    @haxpor @Ed_bt
     
  12. dingxiuweiUnity

    dingxiuweiUnity

    Joined:
    Dec 27, 2016
    Posts:
    5
    @Ed_bt @haxpor @JoshPeterson
    I found if change framework‘s Mach-O Type to Dynamic Library 。This problem will be solved!
    But why?
     
  13. Makro-

    Makro-

    Joined:
    Jun 10, 2015
    Posts:
    6
    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.
     
  14. forest_linshs

    forest_linshs

    Joined:
    Jan 6, 2010
    Posts:
    39
    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.
     
  15. lightmapper

    lightmapper

    Joined:
    Jan 14, 2015
    Posts:
    27
    @Makro- I am encountering the same issue - any luck getting past this?
     
  16. Makro-

    Makro-

    Joined:
    Jun 10, 2015
    Posts:
    6
    @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.

    @lightmapper No luck so far.
     
  17. yuri9163

    yuri9163

    Joined:
    Sep 7, 2017
    Posts:
    5
    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.

    Thanks in advance,
     
    YueyZhou and hispida like this.
  18. YueyZhou

    YueyZhou

    Joined:
    Mar 31, 2017
    Posts:
    1
    Do you have any idea of this?
     
  19. hispida

    hispida

    Joined:
    Jul 14, 2016
    Posts:
    4
  20. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    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.

    I have a sample project here which demonstrates this for iOS and Android: https://github.com/samizzo/UnityNativePrototype

    -sam
     
  21. U_tansuo

    U_tansuo

    Joined:
    Dec 6, 2013
    Posts:
    5
  22. a574392788

    a574392788

    Joined:
    Apr 22, 2019
    Posts:
    1
  23. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    Starting with Unity 2019.3.a2 Unity as a Library feature introduced to make embedding work out of the box.
     
    samizzo likes this.