Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using Unity as a library in native iOS/Android apps

Discussion in '2019.3 Beta' started by PavelLU, May 27, 2019.

  1. ArielVardy

    ArielVardy

    Joined:
    Jun 19, 2017
    Posts:
    2
    Hi, is there any way to build iOS xcode projects in the same structure as in previous versions of unity. We are not interested currently in unity as a library and the fact that you take all third party plugins and bundle them up as one framework (unityFramework) is causing some overhead.

    Thanks,
     
    BinaryBanana likes this.
  2. yurykorzun

    yurykorzun

    Joined:
    Oct 29, 2015
    Posts:
    41
    It looks like the build process is now different and there is now way to make it build a project the old way.
     
  3. Krusty666

    Krusty666

    Joined:
    Feb 24, 2020
    Posts:
    5
    Hi,
    "Unity as a library feature brings some change to API and Xcode project structure. For the most use cases everything will work as before but if you developing or using plugins, custom BuildPostProcessor, PBXProject, CI there is risk these changes affecting your project even if you do not use Unity as a Library feature."

    This is really bad, because it seems impossible to me to write a plugin by integrating swift code. The whole bridging header stuff is completely broken. I can't make my swift code accessible. Is there a workaround or some trick I should know?

    The problem is, there is no support for BridgingHeaders in framework targets
     
    Last edited: Feb 26, 2020
  4. SKArctop

    SKArctop

    Joined:
    Feb 12, 2018
    Posts:
    37
    How would I go about passing command line arguments to a UAAL instance running inside a native Android app?
     
  5. PROTOCUBE_JOB

    PROTOCUBE_JOB

    Joined:
    Oct 22, 2014
    Posts:
    3
    Hi everyone, is it still true that Unity as Library only supports full screen mode?
    Is there a solution to use this integration method, or another method (hoping it's just as simple), to embed Unity in a native Swift app and render it only in a portion of the screen?

    Many thanks for the help.
     
    zivmahluf likes this.
  6. julienfabre

    julienfabre

    Joined:
    Jul 13, 2018
    Posts:
    1
    Hi, is there any update on how to use unity as a library with react native?
     
    artemio_morales likes this.
  7. JonOssoVR

    JonOssoVR

    Joined:
    Mar 15, 2018
    Posts:
    2
  8. lumeneo

    lumeneo

    Joined:
    Mar 3, 2014
    Posts:
    60
    I'd like to use Unity inside an audio plugin, inside a Mac/PC DAW (like Logic or Ableton). Feasible?
     
  9. sandeepsmartest

    sandeepsmartest

    Joined:
    Nov 7, 2012
    Posts:
    138
    Hey guys,Can we load unity in background by masking unity view with some ios/android stuff?is this possible?This is to give users a seamless experience by opening unity in jet speed.There are many steps that user would be doing before launching/opening Unity.So, I would like to utilise this intermediate navigation area to load unity in background.Can someone point me in right direction.Thanks in advance
     
  10. joshuaGnol

    joshuaGnol

    Joined:
    Feb 10, 2020
    Posts:
    4
  11. smartinetz

    smartinetz

    Joined:
    Dec 8, 2017
    Posts:
    49
    Did anybody ever manage to get this running in Xamarin.iOS?
    I know that there is an example how it's done in Android.

    Regards
     
  12. pushpendra996

    pushpendra996

    Joined:
    Dec 8, 2018
    Posts:
    4
    As per instruction this is not possible. But can we use multiple UnityLibrary in the native android project? I want to open the unity module on different - 2 button clicks. Let say first button click first game, And if the user clicks on the second button then I want to open the second game. is it possible? If yes then HOW?

    I tried this, But in my case when I open first game activity then it's opening first game, But when I am opening second game activity then also it's opening only first game. In concussion, I am not able to open a different game.
     
  13. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    I don't think that is possible without extra wizardry. At least, not in the way you described.

    What you could do is put booth of your games in the same Unity project. This could be as simple as making your two games into packages and having your main project contain some switching logic. The app would send a message to the Unity part then it would load the correct game based on the content of the message.
     
  14. BinaryBanana

    BinaryBanana

    Joined:
    Mar 17, 2014
    Posts:
    81
    Since this is now enabled by default in Unity 2019.3, is there a way to turn it off? We are not ready to deploy the app with Unity as a library. I want to continue building the old way. Is it possible?
     
    Menion-Leah and MagicMiikka like this.
  15. Starship0225

    Starship0225

    Joined:
    Nov 17, 2017
    Posts:
    3
    I'm trying to make status bar and navigation bar visible on Android using Unity as a library.
    When UnityPlayerActivity starts, it goes to full-screen.
    I found out that only full-screen mode is supported for rendering but is it not even possible to
    show status bar or navigation bar overlay as on top of the screen?
    Anyone know how to achieve this?
     
    Last edited: Jun 12, 2020
  16. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Do you have the "Render Over Native UI" checkbox checked in the player settings?
     
  17. Starship0225

    Starship0225

    Joined:
    Nov 17, 2017
    Posts:
    3
    I've tried them both on and off but still doesn't work...
     
  18. MagicMiikka

    MagicMiikka

    Joined:
    Aug 23, 2014
    Posts:
    14
    I am having issues with configuring the gradle with third party sdks.

    For HelpShift:
    A problem occurred evaluating project ':unityLibrary'.
    Project with path ':helpshift-plugin-wrapper' could not be found in project ':unityLibrary'.

    OneSignal troubleshooting also refers that there is an issue with root build.gradle and for them the workaround is the following:
    https://documentation.onesignal.com/docs/troubleshooting-unity#unity-20193-or-newer

    Any pointers?
     
  19. dustinkerstein

    dustinkerstein

    Joined:
    Jan 26, 2017
    Posts:
    16
    @btristan and @Starship0225, were you able to get this working? I'm curious if it's possible to render a "normal" looking Android/iOS app that has essentially a photo gallery powered by Unity.
     
  20. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Yes it is possible. I contributed to an app that uses Unity to display some graphics and uses the native Android UI over it. It was a bit difficult to make work. We made our own Android app that takes in the Unity as a Library output. But instead of using the built-in Unity activity that comes in the library, we use our own activity (with its own UI) and starts Unity the same way the default Unity activity does. Poke around in the library after importing it into our Android project and you should see how it is done. There isn't a lot of Java code in the library.
     
  21. dustinkerstein

    dustinkerstein

    Joined:
    Jan 26, 2017
    Posts:
    16
    Thanks @btristan, it sounds like you were able to build the Android app from the ground up to support the Unity library. Do you think it would be feasible (without an immense restructuring) to take an existing production Android app (for example a e-commerce app), and plugin the Unity library to act as the app's photo gallery?
     
  22. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    I should have re-worded my post.

    This is exactly what we did. We had an existing app that was doing some intensive graphics with the regular Android APIs but as the graphical needs scaled the performance got much worse. (thing 1-2 FPS) So we replaced that with Unity but kept all the regular Android menus.

    It was a TON of work but the critical part was that the UI was already in a Fragment so we just needed to replace the Activity that was showing the graphics. Making that Activity operate the same way as the Unity was very complicated.

    Customizing the default Unity Activity is no joke but I think some of my app's difficulty was because the existing code was already complicated and it made everything harder.

    Another weird thing is that if you tell Unity to shut down it will kill your app. (literally calls kill on it's own PID) So if you start the Unity code you can't shut it off again.
     
  23. dustinkerstein

    dustinkerstein

    Joined:
    Jan 26, 2017
    Posts:
    16
    Got it @btristan, thanks! Do you feel that any of the work you did could be boilerplate for another non-related Android app, or is it always going to be a huge custom job?
     
  24. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    The stuff made for my app is very coupled to the app but it probably could be made into boiler-plate. Unfortunately I wouldn't be able to share any of it due to company policies.
     
  25. dustinkerstein

    dustinkerstein

    Joined:
    Jan 26, 2017
    Posts:
    16
    K, good to know. Thanks again. I'd definitely love to see this done as boilerplate for iOS/Android. Would save a huge amount of work for folks interested in doing this which if it was easier I imagine there could be many... If anyone is interested in tackling this, I'm happy to pay a bounty. Send me a PM if interested.
     
  26. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    I'm not suggesting you do this and Unity might tell you not to because it violates so user agreement (IDK if it does) but... from a technical standpoint you could always decompile Unity's Java classes (Android Studio will let you do this) to see how they work.
     
    dustinkerstein likes this.
  27. Pretorianunity1978

    Pretorianunity1978

    Joined:
    Oct 27, 2015
    Posts:
    2
    will Unity as a Library work with Android app written in javascript?
     
  28. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    I just started using UaaL with Unity 2019.4.10. We got our Unity app to run within a native iOS app, and that's working great.

    The unloading is not working though.

    We are using unloadApplication that is provided by UnityFramework.h, and we are getting the proper response from the registered unityDidUnload. So Unity is doing something, but:
    1. the memory is not released
    2. the game objects are not destroyed. they don't carry their state - it's almost like they persist but with default values

    Is there anything else that is needed? Or is the unloadApplication provided by UaaL not working?
     
    Last edited: Sep 25, 2020
    NSWell likes this.
  29. auerfloriancom

    auerfloriancom

    Joined:
    Jan 17, 2019
    Posts:
    3
  30. rahul-Mlympix

    rahul-Mlympix

    Joined:
    Oct 5, 2020
    Posts:
    2
    Is there any way to integrate multiple unity projects in android studio?
     
  31. coolrukshan

    coolrukshan

    Joined:
    Oct 12, 2020
    Posts:
    1
    I have tried this and I can see there is a separate app is installed for the Unity lib with the same name as my android app. so it's the normal way it's worked or can i run the Unity part totally inside my android app without installing a separate app for Unity Lib?
     
  32. gurupj

    gurupj

    Joined:
    Oct 4, 2018
    Posts:
    2
    Hi,

    Project has a requirement of having Unity3D Library to be exported and used inside Android Native. All working fine now until I tried to have Agora Plugin to be integrated inside Unity3D and exported the project as Library. I am seeing
    settings.gradle is having : implementation project('AgoraRtcEngineKit.plugin') in it. I am Seeing Inside Folder of androidBuild/unityLibrary/AgoraRtcEngineKit.plugin

    But I get the Compiler error on Gradle sync : Project with path ':unityLibrary\AgoraRtcEngineKit.plugin' could not be found in project ':app'.

    I moved the Plugins folder to the Assets Root folder, even then same issue.

    note : I am using Unity3d.2019.4.7 LTS and Android Studio 4.0.1

    Please help me out, tried a lot on this
     
  33. ssidhant

    ssidhant

    Joined:
    Sep 9, 2019
    Posts:
    8
    Can AR foundation be packaged as part of this unity library for native consumption?
     
    fabischn_ethz and ROBYER1 like this.
  34. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,444
    Support for React Native please?
     
    fabischn_ethz likes this.
  35. MarcSpraragen

    MarcSpraragen

    Joined:
    Jun 29, 2020
    Posts:
    8
    Can Unity, as a library in a native Android app, load files (video, sound, etc) from the Android app's res or asset folders?
    I've seen several ways to share Unity assets with the main native app (streaming assets, etc.) but not much about the other direction. Thanks!
     
  36. chris_unity549

    chris_unity549

    Joined:
    Aug 28, 2020
    Posts:
    6
  37. RobW81

    RobW81

    Joined:
    Sep 1, 2012
    Posts:
    3
    I appear to be getting memory issues when loading my app inside WPF using the the UnityPlayer.dll.

    I have implemented the first solution using the .exe and -parentHWND by starting the .exe and embedding it inside of my WPF Panel. That works fine but I have some weird touch screen issues when switch between WPF and Unity.

    To try and fix the issues I tried the second solution of loading UnityPlayer.dll into my app using
    Code (CSharp):
    1. [DllImport("UnityPlayer.dll", EntryPoint = "UnityMain", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
    This is loading the app but now I get out of memory errors and errors in the log files

    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak
    (Filename: Line: 554)

    Any ideas why the same build would throw these errors but the .exe version doesn't?
     
  38. Javier-Lingo

    Javier-Lingo

    Joined:
    Nov 20, 2018
    Posts:
    6
    Hi!

    We recently updated our hybrid React Native + Unity app to use Unity As a Library, and found out that on Android the safe area is no longer reported (Unity just returns the entire display on Android, ignoring notches/insets/cutouts; iOS works fine). Has anyone else run into this? Is this a known issue or is there some caveats / trickery involved in getting that bit to work?

    TIA,
    Javier
     
  39. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Check under Player Setings->Resolution And Presentation->Render Outside Safe Area
     
  40. Javier-Lingo

    Javier-Lingo

    Joined:
    Nov 20, 2018
    Posts:
    6
    It is enabled, and we are indeed rendering to the full display on both Android and iOS as expected.

    But we can't detect the safe area correctly on Android in order to adjust the layout of interactive elements. On iOS it works, returns the correct safe subrect and we safely avoid notches and such; but on Android the Screen.safeArea just returns the entire display.

    We're on 2020.1.17. Before moving to UaaL, the same use of Screen.safeArea returned a properly reduced rect in this Android device (roughly 100 pixels eaten by the notch), and all others.
     
    Last edited: Mar 30, 2021
  41. Javier-Lingo

    Javier-Lingo

    Joined:
    Nov 20, 2018
    Posts:
    6
    I just added a debug log to the uaal-example Unity git repo

    Code (CSharp):
    1.     void ChangeColor(string newColor)
    2.     {
    3.         Debug.Log($"Screen size is {Screen.width}x{Screen.height}, safe rect: {Screen.safeArea}");
    4.         ...
    and it exhibits the same behaviour: safe area == full display, does not exclude notches or rounded corner cutouts.

    Code (csharp):
    1. Screen size is 1080x2340, safe rect: (x:0.00, y:0.00, width:1080.00, height:2340.00)
    If I build and run just the unity project (without the uaal wrapper) in the same Android device, the expected log with the correct safe area:

    Code (csharp):
    1. Screen size is 1080x2340, safe rect: (x:0.00, y:0.00, width:1080.00, height:2240.00)
    Standalone without uaal, it works both build & run inside unity, or exporting and building inside Android Studio.
     
    Last edited: Mar 30, 2021
  42. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,663
    Try disabling it.
     
  43. Javier-Lingo

    Javier-Lingo

    Joined:
    Nov 20, 2018
    Posts:
    6
    If I disable it, then as expected Unity only renders inside the safe zone, leaving the notch area black. It reports a smaller display, and a full screen safe zone (for the smaller area):
    Code (csharp):
    1. Screen size is 1080x2240, safe rect: (x:0.00, y:0.00, width:1080.00, height:2240.00)
    It's interesting that in uaal Unity can see the notch area for this flag, but can't report the Screen.safeArea correctly. But I still need to fiigure out how to achieve full display rendering while having a correct Screen.safeArea.

    FWIW, Screen.cutouts also does not report any cutouts in uaal, while in standalone it contains the safe area rect as cutout.
     
    Last edited: Mar 30, 2021
  44. Javier-Lingo

    Javier-Lingo

    Joined:
    Nov 20, 2018
    Posts:
    6
    I have added an ids.xml file to the example project similar to what the standalone unity-generated project has, and the example now works. The file sits at
    NativeAndroidApp/app/src/main/res/values/ids.xml
    and its contents are:

    Code (csharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <resources>
    3.     <item type="id" name="unitySurfaceView" />
    4. </resources>
    I'm going to try this in our app. I have no idea what any of it means but crossing fingers anyway. I can't find references anywhere in the uaal API or sample to
    unitySurfaceView
    , so it's not quite obvious that it's necessary.

    [edit: it worked and fixed our issues. The uaal sample, if not the uaal system itself, should probably get this fix]
     
    Last edited: Mar 31, 2021
  45. mattbrandmm

    mattbrandmm

    Joined:
    Jun 5, 2018
    Posts:
    90
    NSWell, ROBYER1 and nilsdr like this.
  46. joel-agora_io

    joel-agora_io

    Joined:
    Mar 4, 2020
    Posts:
    5

    @gurupj if you or anyone else is having trouble with integrating Agora into Unity, you can find a support slack at agoraiodev.slack.com #unity-help-me where we will get back to your question within 24 hours. For any Agora related questions we can best support you on Slack, Stack Overflow, or Twitter @JoelThomas362.

    Cheers!
     
  47. Ayoub_Gharbi

    Ayoub_Gharbi

    Joined:
    Jan 5, 2021
    Posts:
    3
    Did anyone test using Unity as a library to build App Clips?
    How would you approach that? I would like to get your insight around it.
     
  48. NSWell

    NSWell

    Joined:
    Jul 30, 2017
    Posts:
    89
    You cannot do this. Because the Unity framework exceeds 10M.
    If you are only testing, then it is no different from ordinary embedding

    This is my test demo:
    https://youtube.com/shorts/DFYkswPJLr4?feature=share
     
  49. Ayoub_Gharbi

    Ayoub_Gharbi

    Joined:
    Jan 5, 2021
    Posts:
    3
    Thanks, @NSWell - did you use Unity for this App Clip? how did you manage the size?
     
  50. NSWell

    NSWell

    Joined:
    Jul 30, 2017
    Posts:
    89
    @Ayoub_Gharbi Yes. It is embed Unity. But the package size over than 10M. Because the
    Unity framework.framework
    reached 38M. It can not upload to the app store.

    How to know App clip package size?
    • If you archive your app, it will generate an entry in the Organizer (under Window).

    • Right click that archive, then show it in the Finder.

    • Right click the .xcarchive file, Show Package Contents

    • Drill down through Products into Application

    • Right click the application and Show Package Contents

    • You'll find a folder name "AppClips" that has the app clip application

    • Verify it's size

    • If it's size is too big, again Show Package Contents

    • The culprits are usually frameworks or assets files(UnityFramework.framework)
     
    Ayoub_Gharbi likes this.