Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Integration Unity as a library in native Android app Version 2

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

  1. Overature

    Overature

    Joined:
    May 10, 2020
    Posts:
    25
    Hi, I had a similar problem and came up with a solution that should work for you. After exporting your unity project you need to manually import into Android studio each of the .aar files that is present in your exported library, (unityLibrary/libs). To do this in AS, go to File - New - Import .JAR/.AAR Package, and select the .aar file. Do this for all the .aar files.

    Then in your build.gradle (Module:app) file add each .aar to the dependencies section. The same way that you added the "implementation project(':unityLibrary')" before. For me one of them was: "implementation project(':arcore_client')"
    You don't need to implement files trees for these one.

    Then in the build.gradle(Module: unityLibrary), as you have above, you need to delete each of the implementations that are automatically added. Leave the top file tree one.

    That should work for you!
     
  2. adam_sutcliffe

    adam_sutcliffe

    Joined:
    May 18, 2017
    Posts:
    3
    I'm having display issues when it comes to running the framework on an android device, my game works fine in the Unity sim, and on iOS, but a `build and run` or project export both cause very weird display issues as seen in the attached picture. I've tried all permutations of the rendering settings in the Player Settings but to no avail. Anyone else had this issue?
     

    Attached Files:

  3. bobejner96

    bobejner96

    Joined:
    Aug 15, 2020
    Posts:
    3
    Hi everyone,

    I've got this error constantly, can not make any progress further. I followed all suggested instructions for setup.
    Trying to build AR Foundation for RN app. Unity build passes ok, but this i stuck at run-android of react native project.

    Could not find method implementation() for arguments [project ':unityLibrary'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

    Any ideas?

    Unity: 2020.1.2f

    Thanks!
     
  4. joasus12345

    joasus12345

    Joined:
    Dec 26, 2018
    Posts:
    14
    I was running into an error in which I can't reopen the game for a second time. I'm using a bottom navigation activity and from one of the fragments I launch unity. But the while app crashes when trying to open the unity player activity for a second time
    Null pointer dereference and segmentation fault.
    I see that it may be related to these (screenshots and links) but wasn't able to get a fix yet. I've been trying for a long time now
    The screenshots are from this link, the version 1 tutorial: https://forum.unity.com/threads/integration-unity-as-a-library-in-native-android-app.685240/
    If someone could link me to the case1163573 mentioned then that would be great as well
     

    Attached Files:

  5. silverduck

    silverduck

    Joined:
    May 16, 2010
    Posts:
    27
    I've got this all working except that when the Unity activity is launched, it doesn't display my Static Splash Image. I just upgraded to Unity 2019.4.8f1. Before then, I had Unity integrated into my native Android app using the unofficial unsupported methods and the Splash Image always appeared as intended. I'm not sure why it's not showing up now.

    Are there any special considerations that are required now to get splash images or such to appear?
     
  6. adam_sutcliffe

    adam_sutcliffe

    Joined:
    May 18, 2017
    Posts:
    3
    I've got an issue with the the `libmain.so` failing to load as the library isn't found. Any ideas what could cause this? I've done the setup and integration as instructed. The build is fine then on click of 'Show Unity' button I get this error:
    Unity: Failed to load 'libmain.so', the application will terminate.


    Code (JavaScript):
    1. AndroidRuntime: FATAL EXCEPTION: main
    2.     Process: com.brainbow.peak.app, PID: 31512
    3.     java.lang.UnsatisfiedLinkError: dlopen failed: library "libmain.so" not found
    4.         at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
    5.         at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
    6.         at java.lang.System.loadLibrary(System.java:1664)
    7.         at com.unity3d.player.UnityPlayer.<clinit>(Unknown Source:13)
    8.         at com.unity3d.player.UnityPlayerActivity.onCreate(UnityPlayerActivity.java:41)
    9.         at com.brainbow.unitygameframework.OverrideUnityActivity.onCreate(OverrideUnityActivity.java:31)
    10.         at com.brainbow.peak.app.ui.gamelauncher.MainUnityGameActivity.onCreate(MainUnityGameActivity.java:11)
    11.         at android.app.Activity.performCreate(Activity.java:7995)
    12.         at android.app.Activity.performCreate(Activity.java:7979)
    13.         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
    14.         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
    15.         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
    16.         at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    17.         at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    18.         at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    19.         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
    20.         at android.os.Handler.dispatchMessage(Handler.java:106)
    21.         at android.os.Looper.loop(Looper.java:223)
    22.         at android.app.ActivityThread.main(ActivityThread.java:7656)
    23.         at java.lang.reflect.Method.invoke(Native Method)
    24.         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    25.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     
  7. adam_sutcliffe

    adam_sutcliffe

    Joined:
    May 18, 2017
    Posts:
    3
    Okay so I think I've found the cause of this issue, I hadn't updated my custom activity to use a separate process in the manifest as the one in the example does. That being said my main app uses Firebase for a variety of tasks and this has now thrown up more new and exciting errors :mad:
     
  8. bobejner96

    bobejner96

    Joined:
    Aug 15, 2020
    Posts:
    3
    Ok, so i got it working.
    My goal was to integrate Unity with ReactNative.
    I think there was missmatch in some versions between, so at the and i used:
    Unity 2019.3 and nreact-native-unity-view package from npm site.

    My goal is to achieve AR Foundation + ARKit/Core experience in ReactNative app. And now i am stucked with ImageTracking on iOS. Same case as number #8 on this: https://forum.unity.com/threads/ar-foundation-2-0-image-target-ios-problem.685498/ . Any ideas maybe?
     
  9. MuuM

    MuuM

    Joined:
    Aug 4, 2017
    Posts:
    4
     
  10. MuuM

    MuuM

    Joined:
    Aug 4, 2017
    Posts:
    4
    @
    When I use VideoPlayer to Play a Video,But It can not work in Android Native
     
  11. IonutPutinica

    IonutPutinica

    Joined:
    Sep 13, 2020
    Posts:
    1
    Hey guys, I followed the tutorial, but it seems that I am getting a bunch of errors, would someone mind taking a look and give me a hint on what might be happening? I want to mention that I tried to also run the official project that is linked in the tutorial, but not even that one runs, giving me a similar set of errors to what my project is giving
    https://imgur.com/a/iSwXvWj
     
    john_goren likes this.
  12. DaniilK711

    DaniilK711

    Joined:
    Sep 21, 2020
    Posts:
    3
    Where in the code the Unity buttons are? I found the Android buttons that I can move around and so on, but I dont see the Unity buttons that are transparent in color
     
  13. DaniilK711

    DaniilK711

    Joined:
    Sep 21, 2020
    Posts:
    3
    Who ever comes in here with the same question buttons are in the Cube.cs. It is so disorganized :(((
     
  14. Deleted User

    Deleted User

    Guest

    Hi! Did someone find the answer to that question?

    I'm stuck in this point... Thanks!
     
  15. nss2

    nss2

    Joined:
    Feb 28, 2019
    Posts:
    2
    Hi, currently I'm testing the sample using Unity 2020.1.6f1 for Android. Everything goes fine until I want to Run it on a device, it shows an error with c++ files:
    I Exported using IL2CPP Backend.
    upload_2020-11-4_16-59-35.png

    If anyone has a solution for this, please tell me, thanks.
     
    john_goren likes this.
  16. Overature

    Overature

    Joined:
    May 10, 2020
    Posts:
    25
    You should try setting the APi Compatibility level to .NET 4.x. That is what I have.
     
  17. AIStudio

    AIStudio

    Joined:
    Apr 10, 2017
    Posts:
    3
    How solve this error?
     
  18. Overature

    Overature

    Joined:
    May 10, 2020
    Posts:
    25
    Every time you export the Unity project to AS, then AS will add those implementation names to the build.gradle (module unityLibrary) file. see my previous comment:

    Hi, I had a similar problem and came up with a solution that should work for you. After exporting your unity project you need to manually import into Android studio each of the .aar files that is present in your exported library, (unityLibrary/libs). To do this in AS, go to File - New - Import .JAR/.AAR Package, and select the .aar file. Do this for all the .aar files.

    Then in your build.gradle (Module:app) file add each .aar to the dependencies section. The same way that you added the "implementation project(':unityLibrary')" before. For me one of them was: "implementation project(':arcore_client')"
    You don't need to implement files trees for these one.

    Then in the build.gradle(Module: unityLibrary), as you have above, you need to delete each of the implementations that are automatically added. Leave the top file tree one.
     
  19. chris_unity549

    chris_unity549

    Joined:
    Aug 28, 2020
    Posts:
    7
  20. andreibacch

    andreibacch

    Joined:
    Dec 19, 2020
    Posts:
    3
    Calling unload and trying to start the UnityPlayer again causes a SISEGV crash. Can you please tell me exactly how to accomplish this unload pattern?

    I'm trying to run the UnityPlayer on Android in the same process as the app. I'm calling unload before destroying the activity that's hosting UnityPlayer. That works fine. When coming back to the activity though, and starting the UnityPlayer once again, it crashes like so:

    Code (CSharp):
    1. 2021-01-14 18:52:23.116 28566-32459/com.bacch.androidemo E/AndroidRuntime: FATAL EXCEPTION: UnityMain
    2.     Process: com.bacch.androidemo, PID: 28566
    3.     java.lang.Error: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    4.     Version '2019.4.11f1 (2d9804dddde7)', Build type 'Development', Scripting Backend 'il2cpp', CPU 'arm64-v8a'
    5.     Build fingerprint: 'samsung/gts4lwifixx/gts4lwifi:10/QP1A.190711.020/T830XXU4CTJ1:user/release-keys'
    6.     Revision: '7'
    7.     ABI: 'arm64'
    8.     Timestamp: 2021-01-14 18:52:22+0200
    9.     pid: 28566, tid: 32459, name: UnityMain  >>> com.bacch.androidemo <<<
    10.     uid: 10455
    11.     signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
    12.     Cause: null pointer dereference
    13.         x0  0000000000000000  x1  0000000000000000  x2  0000000000000000  x3  0000000000000041
    14.         x4  0000000000000021  x5  6563ffffffffffff  x6  0000000000000000  x7  0000008000000000
    15.         x8  000000778cc072d8  x9  0000000000000001  x10 0000000000000000  x11 0000000000000000
    16.         x12 0101010101010101  x13 0000000000000005  x14 0000000000000000  x15 0000ea98f753d4f8
    17.         x16 00000077ccce6900  x17 00000078b82776f0  x18 0000007789f96000  x19 00000077896e7d18
    18.         x20 00000077896e7d10  x21 0000000000000000  x22 000000778cc05950  x23 00000077c6be914f
    19.         x24 0000000000000004  x25 000000778cc07020  x26 000000782baab4b0  x27 0000000000000001
    20.         x28 000000778cc056e0  x29 000000778cc056e0
    21.         sp  000000778cc05460  lr  00000077cbcd6a94  pc  00000077cbcd6a94
    22.    
    23.     backtrace:
    24.           #00 pc 000000000067fa94  /data/app/com.bacch.androidemo--VinOgfdD1qG_nG4wsylTw==/base.apk (BuildId: d56f4052c5adf991c99fcd47dc6217de65f73146)
    25.           #01 pc 000000000065443c  /data/app/com.bacch.androidemo--VinOgfdD1qG_nG4wsylTw==/base.apk (BuildId: d56f4052c5adf991c99fcd47dc6217de65f73146)
    26.           #02 pc 000000000067ff5c  /data/app/com.bacch.androidemo--VinOgfdD1qG_nG4wsylTw==/base.apk (BuildId: d56f4052c5adf991c99fcd47dc6217de65f73146)
    27.           #03 pc 0000000000658084  /data/app/com.bacch.androidemo--VinOgfdD1qG_nG4wsylTw==/base.apk (BuildId: d56f4052c5adf991c99fcd47dc6217de65f73146)
    28.           #04 pc 00000000006824b4  /data/app/com.bacch.androidemo--VinOgfdD1qG_nG4wsylTw==/base.apk (BuildId: d56f4052c5adf991c99fcd47dc6217de65f73146)
    29.           #05 pc 0000000000140350  /apex/com.android.runtime/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    30.           #06 pc 0000000000137334  /apex/com.android.runtime/lib64/libart.so (art_quick_invoke_stub+548) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    31.           #07 pc 0000000000145fec  /apex/com.android.runtime/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+244) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    32.           #08 pc 00000000002e3750  /apex/com.android.runtime/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+384) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    33.           #09 pc 00000000002de9b0  /apex/com.android.runtime/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+892) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    34.           #10 pc 00000000005a3568  /apex/com.android.runtime/lib64/libart.so (MterpInvokeDirect+424) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    35.           #11 pc 0000000000131914  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_direct+20) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    36.           #12 pc 00000000005a3fb0  /apex/com.android.runtime/lib64/libart.so (MterpInvokeStatic+1040) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    37.           #13 pc 0000000000131994  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_static+20) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    38.           #14 pc 00000000005a2d20  /apex/com.android.runtime/lib64/libart.so (MterpInvokeInterface+1788) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    39.           #15 pc 0000000000131a14  /apex/com.android.runtime/lib64/libart.so (mterp_op_invoke_interface+20) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    40. 2021-01-14 18:52:23.118 28566-32459/com.bacch.androidemo E/AndroidRuntime:       #16 pc 00000000002b4a64  /apex/com.android.runtime/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.12109930742295516082)+240) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    41.           #17 pc 00000000005927a8  /apex/com.android.runtime/lib64/libart.so (artQuickToInterpreterBridge+1032) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    42.           #18 pc 0000000000140468  /apex/com.android.runtime/lib64/libart.so (art_quick_to_interpreter_bridge+88) (BuildId: ba99912d54be0cff337b2a5059f6d2f7)
    43.           #19 pc 0000000002068d3c  /memfd:/jit-cache (deleted)
    44.    
    45.         at base.0x67fa94(Native Method)
    46.         at base.0x65443c(Native Method)
    47.         at base.0x67ff5c(Native Method)
    48.         at base.0x658084(Native Method)
    49.         at base.0x6824b4(Native Method)
    50.         at libart.art_quick_generic_jni_trampoline(art_quick_generic_jni_trampoline:144)
    51.         at libart.art_quick_invoke_stub(art_quick_invoke_stub:548)
    52.         at libart.art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)(Invoke:244)
    53.         at libart.art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)(ArtInterpreterToCompiledCodeBridge:384)
    54.         at libart.bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)(DoCall<false, false>:892)
    55.         at libart.MterpInvokeDirect(MterpInvokeDirect:424)
    56.         at libart.mterp_op_invoke_direct(mterp_op_invoke_direct:20)
    57.         at libart.MterpInvokeStatic(MterpInvokeStatic:1040)
    58.         at libart.mterp_op_invoke_static(mterp_op_invoke_static:20)
    59.         at libart.MterpInvokeInterface(MterpInvokeInterface:1788)
    60.         at libart.mterp_op_invoke_interface(mterp_op_invoke_interface:20)
    61.         at libart.art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.llvm.12109930742295516082)(Execute:240)
    62.         at libart.artQuickToInterpreterBridge(artQuickToInterpreterBridge:1032)
    63.         at libart.art_quick_to_interpreter_bridge(art_quick_to_interpreter_bridge:88)
    64.         at jit-cache (deleted).0x2068d3c(Native Method)
    65.  
     
  21. unity_DlCazeYImtT3qg

    unity_DlCazeYImtT3qg

    Joined:
    Jul 1, 2020
    Posts:
    1
    Hello everyone,

    When I run the app on my device (Android) with Android Studio and with the full example folder everything works fine.

    But when I start a very new project or when i'm using those folders (https://github.com/Unity-Technologies/uaal-example) and follow all the steps, when I run the app and click on "Show Unity" the app crashed every time and without any errors....

    When I look to the UnityProject folder there is a lots of differences between "mine" and the full example folder. And I don't understand why, I'm using the same Unity version....

    Is there some steps missing in the construction/strucutre of the UnityProject folder ?? Why are there so different ?

    I have read that some people got the same issue than me, but I haven't seen any answers.

    Any help will be very welcome !
    Thanks !
     
    ngthlong1990 likes this.
  22. chris_unity549

    chris_unity549

    Joined:
    Aug 28, 2020
    Posts:
    7
    Hello,

    The crash happens because you close the Activity. If you "finish()" the Activity then the UnityPlayer is destroyed and that kills the entire process - which the same process your main app is running. Are you sure the entire app isn't restarted? You can check the error logs for "Broken pipe" or something similar to that.

    If you don't close the Activity and just go back the way the UaaL example does it then you are at the same place we are on my initial post.
     
  23. andreibacch

    andreibacch

    Joined:
    Dec 19, 2020
    Posts:
    3
    @chris_unity549 But I need to kill the activity. I'm distributing this as part of a library to customers. I can't forsee their activity lifecycle/flow and for sure I can't start their own activities for them. Even if I were in charge of the activity lifecycle, what the UaaL example is proposing is a dirty workaround that manipulates the activity lifecycle and is prone to a lot of errors.

    What's even more interesting is that Application.Unload documentation suggests that I should be able to re-run UnityPlayer in the same process however many times I would like. This documentation is proven to be false information.

    "On iOS and Android, unloads the release memory related to Scenes and GameObjects, but keeps a minimal amount of memory that the engine requires. This makes it possible to run Unity again in the same process. For more information, see documentation on Unity as a Library for iOS and Android." - FALSE

    There are a lot of other people on here (one example of many, EDIT (seems it's your post haha) ) who are struggling with this very restrictive behaviour, that pretty much makes the "unity project as android library" feature useless.

    Our company is now considering cancelling the Unity Pro subscriptions we have (about 22 seats) so we can move to a less restrictive platform,.
     
    Last edited: Jan 24, 2021
    wilsnat and dimitris_baud like this.
  24. chris_unity549

    chris_unity549

    Joined:
    Aug 28, 2020
    Posts:
    7
    We are in the same boat as you pretty much. We are creating a module to be distribute to other clients were we have no control over the Activity lifecycle.

    So far we have tried different approach but nothing worked out.

    andreibacch as far as I can understand, Unload works fine if you don't kill the Activity. If the Activity is killed then the resources that Unload kept will be discarded.
     
    Last edited: Jan 20, 2021
    wilsnat and dimitris_baud like this.
  25. dimitris_baud

    dimitris_baud

    Joined:
    Jan 15, 2018
    Posts:
    31
    Dear Unity and @PavelLU,

    Until there is a response or solution to the above, please at least add a large warning to the top of the Post that informs users of this issue so that they don't discover this limitation late in their projects, like some of us.

    Thank you.
     
    MarcSpraragen and john_goren like this.
  26. Frz95

    Frz95

    Joined:
    Apr 29, 2016
    Posts:
    7
    Why my AndroidStudio popup this message ? I followed all the steps and also my device is using Android 9.0, API 28. Can someone help me please.

    upload_2021-2-19_15-27-54.png
    upload_2021-2-19_15-29-19.png
     
  27. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    Is this still the most up to date guide on integration with unity as a library? We have to jump through a lot of hoops to get things to compile correctly, the clues for a lot of which are scattered throughout the forum
     
    ngthlong1990 and john_goren like this.
  28. Overature

    Overature

    Joined:
    May 10, 2020
    Posts:
    25
  29. Frz95

    Frz95

    Joined:
    Apr 29, 2016
    Posts:
    7
  30. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    Try adding this to the application tag of your androidmanifest:

    android:extractNativeLibs="true"
     
    Frz95 likes this.
  31. john_goren

    john_goren

    Joined:
    Mar 19, 2021
    Posts:
    15
    I am having the same experience. Would love to work on a more modern guide with a FAQ for troubleshooting common pitfalls and maybe some more background context as to what is actually going on with the Unity folder.
     
  32. Frz95

    Frz95

    Joined:
    Apr 29, 2016
    Posts:
    7
    Thank you so much ! It works now !!
     
    nilsdr likes this.
  33. Frz95

    Frz95

    Joined:
    Apr 29, 2016
    Posts:
    7
    Hi, I followed all the steps given and managed to display unity in Native app. But when I included the Vuforia package inside Unity, the app can switch from native to Unity, but after it displays the Unity watermark, the screen just becomes black and nothing happen. Can you guys help me ? I'm not expert in migration. TQ in advance.
     

    Attached Files:

    • 1.png
      1.png
      File size:
      20.8 KB
      Views:
      318
    • 2.png
      2.png
      File size:
      42.8 KB
      Views:
      311
    • 3.png
      3.png
      File size:
      62.8 KB
      Views:
      307
    • 4.png
      4.png
      File size:
      66.5 KB
      Views:
      310
    • 5.png
      5.png
      File size:
      52.7 KB
      Views:
      303
  34. john_goren

    john_goren

    Joined:
    Mar 19, 2021
    Posts:
    15
    It sounds like you might be experiencing this common bug: https://stackoverflow.com/questions...m-unity3d-player-unityplayer-nativerestartact
     
  35. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    Check and post your adb logcat output
     
  36. Frz95

    Frz95

    Joined:
    Apr 29, 2016
    Posts:
    7
    This is the error:
    upload_2021-4-26_13-38-51.png

    upload_2021-4-26_13-39-11.png
     
  37. john_goren

    john_goren

    Joined:
    Mar 19, 2021
    Posts:
    15
    For anyone who runs into trouble with this 2019 tutorial technique, especially if struggling with dependency issues:

    I found it was MUCH simpler to just open what Unity has exported, stick my launcher app activity into /launcher/src/main/java/{your namespace here}, assign an Intent filter to launch it, and then watch it just work. Depending on your needs, you may might want to try that more straightforward route first before attempting the technique above. If I had done that first, and trusted my gut, it would have saved a lot of heartache.

    I'm not sure if this is because the tutorial is old or if it's just that my project has finicky Vuforia C++ source objects that caused trouble. (A very simple Unity game without Vuforia seemed to work great with these steps, but as soon as I installed Vuforia, it was build error city.)
     
    Last edited: Apr 27, 2021
  38. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89
    window 10
    Unity 2020.3.1f1
    Android Studio 4.21.

    Build file 'F:\uaal-example-master\UnityProject\androidBuild\unityLibrary\build.gradle' line: 35

    A problem occurred evaluating project ':unityLibrary'.
    > Could not get unknown property 'unityStreamingAssets' for object of type com.android.build.gradle.internal.dsl.AaptOptions.

    [Solved]

    :)create a gradle.properties file in directive:uaal-example-master\NativeAndroidApp,add one line:unityStreamingAssets=.unity3d
     
    Last edited: Jul 3, 2021
  39. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    I found the fix for this, in our case the project build.gradle (unityLibrary) had a path in the jni.srcDirs = [] line because a while ago some files from our il2cpp build caused errors.

    Clearing the '[]' and trying to build again fixed the error "Error: Your project contains C++ files but it is not using a supported native build system."

    Like so:

    Code (CSharp):
    1.     sourceSets {
    2.         main {
    3.             jni.srcDirs = []
    4.         }
    5.     }
     
  40. SKArctop

    SKArctop

    Joined:
    Feb 12, 2018
    Posts:
    38
    Hi.
    We've been sucessfully using this within an application for around 2 years at this point.

    We have recently started a new application, and having an odd issue on Android.

    When ever we close out the GameActivity (Derived from OverrideUnityActivity), essentially calling finish(), our app goes to the correct place, but then re-starts our activity. This only happnes once we close Unity, all other activities when call finish doesn't cause a whole app re-create.

    Anyone had this issue?
     
  41. mekartikshah

    mekartikshah

    Joined:
    Jan 10, 2017
    Posts:
    89
    Hi, I am not able to load the il2cpp.so file to my dynamically downloaded module

    Error I encountered
    JNI FatalError called: Unable to load library: /data/app/com.my_company.integration-0SdCQTzdmkFu2RIaBPQNsQ==/lib/arm64/libil2cpp.so [dlopen failed: library "libil2cpp.so" not found]'

    What I am doing
    I am trying to integrate the unity app in the android app using the dynamic feature of android.

    Steps I followed
    1. I Exported the android project for android studio.
    2. prepared project for dynamic integration (converted library to dynamic feature)
    3. Run the application in mobile (Working fine, no lib not found error)
    4. Test using bundle tool of android (facing the error of libil2cpp.so not found)


    Solution I tried
    1. I tried adding the code
    SplitInstallHelper.loadLibrary(getApplicationContext(),"il2cpp"); and
    java.lang.System.loadLibrary("il2cpp"); before loading the dynamically downloaded module but no change facing the same error.
    2. I checked my aab and apks - all are having the libil2cpp.so inside the jniLibs folder.

    Please let me know if anyone here has the solution to this problem.
     
  42. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    You could try adding android:extractNativeLibs="true" to the <application> element in AndroidManifest.xml
     
  43. drahomirkarchnak

    drahomirkarchnak

    Joined:
    Jan 13, 2022
    Posts:
    2
    This sounds like a problem that was mentioned before in this thread. Unity Activity can't be shutdown peacefully and kills the entire process instead. Wondering if we ever get this one fixed as it's pretty annoying.
     
  44. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    We've achieved this by running Unity in a fragment and giving the process its own name. I can query with our Native Android developer if that isn't helpful enough. Giving Unity its own fragment to run in with a unique name means that it doesn't kill the host process. We can also launch Unity still as its own view for a fullscreen view like they do in the UAAL example app and then we also launch Unity in a fragment to have it shown as a 'subview' within a native window e.g. a smaller view of Unity within a larger native page.
     
  45. tigerss

    tigerss

    Joined:
    Oct 11, 2015
    Posts:
    20
    Hi, I am using Unity as a library inside a native Android application.
    Currently having some issues trying to upgrade from 2019 to the latest LTS version 2020.3.27f1.
    I copied everything from the unity library folder and I see that libil2cpp.so is missing but there are c++ sources to build using gradle.

    I managed to build libil2cpp.so but when running the unity player I get this errors:

    What is missing?
     
  46. Sakshi_09

    Sakshi_09

    Joined:
    Jul 3, 2020
    Posts:
    8
    Hello Everyone,

    I'm using Unity 2020.3.18f1 using the IL2CPP scripting back end for Android. I'm trying to create a SDK using Unity as a library in a Native Android app. When I export the UnityLibrary for Android (ARM64 only) and then creating build/apk of native+unity project then the size of my apk file is increasing by 35mb and i want to reduce the apk size, because total android apk size is becoming 75+mb.

    and when i am creating android apk from unity then the apk size is only 11-12mb.

    Please suggest how can i reduce build size of native app when using unity as a library.
     
  47. NSWell

    NSWell

    Joined:
    Jul 30, 2017
    Posts:
    89
    try to add this `android:extractNativeLibs="true"` for your `AndroidManifest.xml`
    Code (CSharp):
    1.    <application
    2.         android:label="ARMOD"
    3.         android:icon="@mipmap/launcher_icon"
    4.         android:extractNativeLibs="true">
    5.         ....
    6.  
     
  48. Dragovic

    Dragovic

    Joined:
    Jul 23, 2021
    Posts:
    1
    Hi. Im using android studio bumblebee and my build.gradle (Project) doesnt have the circled block:

    So i tried this tutorial:
    (Solution 1 in the video description)

    Then i could add the "allprojects" block and sync my project.

    (this is my build.gradle ( Project) file)
    1.png

    (this is my dependencies in build.gradle ( Module) file)
    build.grandlemodule.png

    (this is my settings.gradle file)
    setting.grandle.png

    But i got this error. I cannot open the "unityLibrary" project folder. It doesnt have the dropdown button. When i clicked on it, the project structure window opened. Untitled.png

    Please help me out!

    Thanks
     
  49. AoGao

    AoGao

    Joined:
    Oct 13, 2019
    Posts:
    1
    I'm also facing this issue. Did you find any solution yet?
     
  50. ngthlong1990

    ngthlong1990

    Joined:
    May 5, 2022
    Posts:
    3
    Hi everyone,
    I have successfully integrated Unity into Android app. However when run on phone, there are two different apps, one Android and one Unity. This is inconvenient. Is there any solution that we can only have only Android app with Unity as a real library, not an additional app included? Thank you.