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
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Integration Unity as a library in native Android app

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

  1. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    [!] Edited Sep 27, 2019. This example is outdated. Since Unity version 2019.3.b4+ is out please refer to Version 2 of the example.

    This post explains how to include Unity as a Library into native Android applications through Activities. (Just in case there is full project ready to build & deploy at the end of this doc ). You can read more about Unity as a Library.

    Pre Requirements:
    • Android Studio 3.3.2+
    • Unity version 2019.3.a2+
    1. Download & Uncompress
    • Unity project
      • This “Unity project” is the sample we want to include in our native Android app
        • Assets / Plugins / Android files have OverrideUnityActivity to extend UnityPlayerActivity
    • Native Android project
      • This is Basic Activity application from Android Studio templates where we want to include our Unity project
        • It have some UI, MainUnityActivity extends OverrideUnityActivity, and is prepared to start MainUnityActivity with Intent
    • For convenience uncompress both projects in same folder:
      image8.png


    2. Generate gradle project for Android platform
    • from Unity Editor open UnityProject
    • at Build Settings (Menu / File / Build Settings)
      • select and switch to Android Platform
      • select option “Export Project”
        image4.png
    • Export UnityProject to androidBuild folder, the folder structure should look like this:
      image10.png
     
    Last edited: Oct 4, 2019
  2. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    3. Add Unity Library module to NativeAndroidApp
    Now we are going to add androidBuild/unityLibrary module to NativeAndroidApp gradle project in Android Studio:
    • open NativeAndroidApp in Android Studio
    • Open settings.gradle
      • At the end of settings.gradle file we add new project pointing to unityLibrary module:
        Code (CSharp):
        1. include ':unityLibrary'
        2. project(':unityLibrary').projectDir=new File('..\\UnityProject\\androidBuild\\unityLibrary')
        image3.png
    • Open build.gradle(Module: app)
      • add the following in dependencies block
        Code (CSharp):
        1. implementation project(':unityLibrary')
        image6.png
    • Open build.gradle(Project: NativeAndroidApp)
      • add the following in allprojects{repositories{ block
        Code (CSharp):
        1. flatDir {
        2.    dirs "${project(':unityLibrary').projectDir}/libs"
        3. }
        repoToUnityLib.png
    • Gradle files have been changed click Sync Now
      image1.png
    • If all went successfully you should see unityLibrary module added in Android view
      image5.png
     
    Last edited: Jun 20, 2019
    TwoTen and cativo23 like this.
  3. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    Project is ready
    Everything is ready to build, run and debug:
    image2.png
    If all went successfully at this point you should be able to run NativeAndroidApp:
    projectReady.png

    Please note after installation to device there will be to icons to launch application, remove <intent-filter>...
    </intent-filter> from AndroidManifest.xml at unityLibrary to leave only integrated version.


    Full Project

    If you have issues following integration steps you can try out fully prepared project ready to build and deploy:
    Download & Uncompress Full Project, open NativeAndroidApp in Android Studio
     
    Last edited: Jun 21, 2019
    TwoTen, btristan, DirkDenzer and 5 others like this.
  4. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    There is a problem with this example: the unload buttons actually quit the app instead of just destroying the activity. (tested on Android 5.1, API level 22)
     
    demo0001, rco-tm and estradap like this.
  5. estradap

    estradap

    Joined:
    Jun 6, 2017
    Posts:
    6
    We have observed that when the UnityPlayerActivity hosting the UnityPlayer object is destroyed, the UnityPlayer calls Process.killProcess(myPid) as part of it's destroy() method. This causes our application to crash and restart since UnityPlayerActivity shares the same process as the application. Is there workaround for this behavior? We do not want to run the the UnityPlayerActivity as a separate process since makes integration with our application much more complicated. Can Unity add support for both types of activities? This would make the Unity library feature much more usable by a wide variety of Android applications, which we believe is the goal of this feature.
     
  6. estradap

    estradap

    Joined:
    Jun 6, 2017
    Posts:
    6
    We have filed a bug report for the Unity Player crashing when performing 'Unload' in the NativeApp since the UnityPlayerActivity calls Process.killProcess instead of exiting cleanly: Case 1163573
     
    rco-tm likes this.
  7. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    Thank you for submitting a bug report, we going to investigate the case and update/fix example/unity accordingly.
     
    rco-tm and KrisNicholsonCF like this.
  8. varun_mani

    varun_mani

    Joined:
    Sep 18, 2018
    Posts:
    7
    Tried this out right now and it seems to work great!
    One weird thing I noticed... I see two "NativeApp" apps installed on my test android device when I build / deploy the NativeApp project from AndroidStudio.

    When I tap on one of them, it launches the Native app correctly and I can go back and forth between Unity and the Android view. But if I launch the other NativeApp app, it launches me straight into the Unity view (i.e. with the spinning cube) and skips the whole Native app layer (obviously, I don't see the native buttons in the middle as well). If I click on the Unity button to take me back to the MainView, I get a NullReference in showHostMainWindow probably beacuse the Main View does not even exist.

    Dev / Test environment: Pixel 2 XL running Android 9 pie. I think I built both the UnityLibrary and the NativeApp using SDK API 28 (Pie). Not sure if this is related but when I tried to do the Gradle sync, after modifying the gradle scripts, it complained that the minSDK version of the NativeApp project was 16 while the minSDK version of the UnityLibrary was 19. So, I changed the NativeApp minSDK value to 19 to get it to build / deploy

    Did I mess something up? Or is it expected that two apps get installed on the device, one native app and another the UnityLibrary?
     
    rco-tm likes this.
  9. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    Expected, it is one app with to 2 <intent-filter><action android:name="android.intent.action.MAIN" />... in AndroidManifest.xml from unityLibrary and another one from app module. For production last most likely should be removed as for this example we tried to keep bare minimum integration steps should be ok, but your right it is confusing doc updated.
     
  10. DirkDenzer

    DirkDenzer

    Joined:
    May 8, 2019
    Posts:
    11
    Hi,

    nice to see such a feature coming with Unity. Also a very nice and detailed explanation, thanks for that.
    However I wanted to mention that I had to add a string to my strings.xml with name game_view_content_description in order to get it running.
    If the string was not defined the UnityActivity crashed when starting it.

    Thought I leave it here in case someone faces the same issue.
     
    ExtremeKaos, biemann and btristan like this.
  11. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    It got me too - hopefully this is in big, bold letters in the documentation. ;P
     
    Voxel-Busters and DirkDenzer like this.
  12. robin_notts

    robin_notts

    Joined:
    Apr 7, 2010
    Posts:
    86
    Any plans to add iOS support in the same way?
     
  13. DirkDenzer

    DirkDenzer

    Joined:
    May 8, 2019
    Posts:
    11
  14. biemann

    biemann

    Joined:
    Jun 28, 2019
    Posts:
    3
    Thanks for this integration.

    To make it work on my own project, I needed in addition to add

    <string name="game_view_content_description">Game view</string>

    to my app's strings.xml file

    and
    Code (CSharp):
    1. defaultConfig {
    2.         ndk {
    3.             abiFilters 'armeabi-v7a', 'x86'
    4.         }
    5.     }
    to my app build.gradle file.
    Otherwise, the app crashed with following error :

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.myapp/com.unity3d.player.UnityPlayerActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
     
    Last edited: Jun 28, 2019
    boctorberk and estradap like this.
  15. aStrangeLoop

    aStrangeLoop

    Joined:
    Feb 17, 2018
    Posts:
    8
    Not sure if this is the place to ask, but where could I find more information about combining this with AR Foundation? (supposedly one of the use-cases of Unity as a library). I managed to put my own game into the example app provided here without encountering any problems, but I'm now trying to put the AR example explained here: https://www.youtube.com/embed/ml9qVRdEH4k into the android app and I'm encountering the following error:

    ERROR: Unable to resolve dependency for ':unityLibrary@debug/compileClasspath': Could not find :arcore_client:


    Can anyone here give me any guidance on how to fix this, or what to google?

    EDIT:

    I managed to resolve the error by changing:
    The dependencies in unityLibrary's build.gradle to

    Code (CSharp):
    1. dependencies {
    2.     implementation fileTree(dir: 'libs', include: ['*.jar'])
    3.     compile files('libs/arcore_client.aar')
    4.     compile files('libs/unityandroidpermissions.aar')
    5.     compile files('libs/UnityARCore.aar')
    6. }
    Now it compiles can open the app, but crashes on pressing the show unity button with the following error
    No implementation found for void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator() (tried Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator and Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator__)


    EDIT:

    Switching to IL2CCP, and turning off Instant Run in Android Studio resolves all error and lets me use launch the AR Core example, very nice.
     
    Last edited: Jul 8, 2019
    alex66rus and obywan like this.
  16. gerdich

    gerdich

    Joined:
    Feb 19, 2016
    Posts:
    10
    I only want to use Audio of Unity in Delphi. Will it be possible with Unity 2019.3a2 to compile a library that I can use in an Android project for Delphi? And IOS? And which banner of Unity will I have to include with the Community edition?
     
    Last edited: Jul 31, 2019
  17. nss2

    nss2

    Joined:
    Feb 28, 2019
    Posts:
    2
    Hi, I tested the example project and it worked correctly.

    Now I'm testing a Unity project with Vuforia exported as an Android Library, and I can't make it work.

    When I launch it from an Android Project it crashes.


    2019-07-31 12:10:53.171 17975-17975/com.unity.mynativeapp E/Unity: Unable to find main
    2019-07-31 12:10:53.209 17975-17975/com.unity.mynativeapp I/HwPointEventFilter: do not support AFT because of no config
    2019-07-31 12:10:53.226 17975-17975/com.unity.mynativeapp E/art: No implementation found for void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator() (tried Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator and Java_com_unity3d_player_UnityPlayer_nativeRestartActivityIndicator__)
    2019-07-31 12:10:53.228 17975-17975/com.unity.mynativeapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.unity.mynativeapp, PID: 17975


    Has anyone tried to use a Vuforia Project as a Library?, if so what's missing?

    Thanks.
     
    Edwin_Lee and sahadha777 like this.
  18. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
    I am working with XCode. Can you provide an example for this, please?
     
  19. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
    Can you provide an example for Unity Integration with Swift?
     
  20. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
    ERROR: Unable to resolve dependency for ':unityLibrary@debug/compileClasspath': Could not find :android_component:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: Failed to resolve: :core-1.1.0:
    Affected Modules: unityLibrary


    ERROR: Unable to resolve dependency for ':unityLibrary@debug/compileClasspath': Could not find :unity_android_bridge:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: Unable to resolve dependency for ':unityLibrary@debugAndroidTest/compileClasspath': Could not find :android_component:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: Unable to resolve dependency for ':unityLibrary@debugAndroidTest/compileClasspath': Could not find :unity_android_bridge:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: Unable to resolve dependency for ':unityLibrary@debugUnitTest/compileClasspath': Could not find :android_component:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: Unable to resolve dependency for ':unityLibrary@debugUnitTest/compileClasspath': Could not find :unity_android_bridge:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
    Remove minSdkVersion and sync project
    Affected Modules: unityLibrary


    WARNING: The targetSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
    Remove targetSdkVersion and sync project
    Affected Modules: unityLibrary


    I got this errror while adding my game scene
     
  21. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
    For me, the problem occurred while integrated the AR Camera(Wikitude)
     
  22. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
     
  23. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
    Tried using Wikitude not working
     
  24. sahadha777

    sahadha777

    Joined:
    Jul 14, 2018
    Posts:
    15
    I am getting this error while integrating Wikitude camera.
    Please help me to solve this error


    ERROR: Unable to resolve dependency for ':unityLibrary@debug/compileClasspath': Could not find :android_component:.
    Show Details
    Affected Modules: unityLibrary


    ERROR: Failed to resolve: :core-1.1.0:
    Affected Modules: unityLibrary


    ERROR: Unable to resolve dependency for ':unityLibrary@debug/compileClasspath': Could not find :unity_android_bridge:.
    Show Details
    Affected Modules: unityLibrary
     
  25. unity_0HhWrJloljIATg

    unity_0HhWrJloljIATg

    Joined:
    May 15, 2019
    Posts:
    3
    Hey, how's it going!

    Trying to build the project using il2cpp. Hoping to build it in ARM64.

    I'm getting a clang linker error both when building the project normally and when exporting the project:
    Code (CSharp):
    1. Failed running D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="unityaot" --compile-cpp --libil2cpp-static --platform="Android" --architecture="ARMv7" --configuration="Release" --outputpath="D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a\libil2cpp.so" --cachedirectory="D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Assets\..\Library\il2cpp_android_armeabi-v7a/il2cpp_cache" --additional-include-directories="D:/Program Files/Unity Editors/2019.3.0a11/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include" --additional-include-directories="D:/Program Files/Unity Editors/2019.3.0a11/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include" --tool-chain-path="D:/Program Files/Unity Editors/2019.3.0a11/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" --profiler-report --map-file-parser="D:/Program Files/Unity Editors/2019.3.0a11/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory=D:/Users/TylerOBrien/Downloads/UnityProject/UnityProject/Temp/StagingArea/assets/bin/Data/Managed --generatedcppdir=D:/Users/TylerOBrien/Downloads/UnityProject/UnityProject/Temp/StagingArea/Il2Cpp/il2cppOutput
    2.  
    3. stdout:
    4. Building libil2cpp.so with AndroidToolChain
    5.     Output directory: D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a
    6.     Cache directory: D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Library\il2cpp_android_armeabi-v7a\il2cpp_cache
    7. ObjectFiles: 132 of which compiled: 0
    8. Total compilation time: 79 milliseconds.
    9. il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"C:\Users\tyler\AppData\Local\Temp\tmpF98D.tmp" -o "D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_2256FF963E93D278D258DA3E8A9F404D\libil2cpp.so" -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id --sysroot "D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\platforms\android-19\arch-arm" -gcc-toolchain "D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -Wl,--wrap,sigaction -nostdlib++ -L "D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\sources\cxx-stl\llvm-libc++\libs\armeabi-v7a" -lc++_static -lc++abi -landroid_support -lunwind -latomic -llog -rdynamic -fuse-ld=bfd.exe
    10.  
    11. D:/Users/TylerOBrien/Downloads/UnityProject/UnityProject/Library/il2cpp_android_armeabi-v7a/il2cpp_cache/8303688318A74DF748FF32B5F88E6CAE.o: In function `NativeAPI_showHostMainWindow_m9D8062DCC54A7E64E4F087FCACBE68872F8D1497':
    12. D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:1672: undefined reference to `showHostMainWindow'
    13. clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
    14.  
    15.  
    16.   at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext)
    17.   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
    18.   at il2cpp.Program.DoRun(String[] args)
    19.   at il2cpp.Program.Run(String[] args)
    20.   at il2cpp.Program.Main(String[] args)
    21. stderr:
    22.  
    23. Unhandled Exception: Unity.IL2CPP.Building.BuilderFailedException: D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"C:\Users\tyler\AppData\Local\Temp\tmpF98D.tmp" -o "D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_2256FF963E93D278D258DA3E8A9F404D\libil2cpp.so" -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id --sysroot "D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\platforms\android-19\arch-arm" -gcc-toolchain "D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -Wl,--wrap,sigaction -nostdlib++ -L "D:\Program Files\Unity Editors\2019.3.0a11\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\sources\cxx-stl\llvm-libc++\libs\armeabi-v7a" -lc++_static -lc++abi -landroid_support -lunwind -latomic -llog -rdynamic -fuse-ld=bfd.exe
    24.  
    25. D:/Users/TylerOBrien/Downloads/UnityProject/UnityProject/Library/il2cpp_android_armeabi-v7a/il2cpp_cache/8303688318A74DF748FF32B5F88E6CAE.o: In function `NativeAPI_showHostMainWindow_m9D8062DCC54A7E64E4F087FCACBE68872F8D1497':
    26. D:\Users\TylerOBrien\Downloads\UnityProject\UnityProject\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:1672: undefined reference to `showHostMainWindow'
    27. clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
    28.  
    29.  
    30.   at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext)
    31.   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
    32.   at il2cpp.Program.DoRun(String[] args)
    33.   at il2cpp.Program.Run(String[] args)
    34.   at il2cpp.Program.Main(String[] args)
    35.  
    36. UnityEngine.Debug:LogError(Object)
    37. UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase)
    38. UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1)
    39. UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String)
    40. UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(Il2CppBuildPipelineData, String, String, Boolean)
    41. UnityEditorInternal.IL2CPPBuilder:Run()
    42. UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry)
    43. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    44.  
     
  26. unity_0HhWrJloljIATg

    unity_0HhWrJloljIATg

    Joined:
    May 15, 2019
    Posts:
    3
    I filed a bug report with the project: fogbugz.unity3d.com/default.asp?1174809_ebr3sj4eac6ar72r.
     
  27. zbagley

    zbagley

    Joined:
    May 23, 2019
    Posts:
    3
    Fresh project on MacOS High Sierra and hitting
    Invalid build path
    with
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)


    upload_2019-8-14_13-4-6.png

    Note: iOS plugin works flawless. Have never run into this issue before. I'm building with the unchange Unity project provided. Similar thread without resolution: https://forum.unity.com/threads/unityengine-guiutility-processevent-int32-intptr.514797/

    Update: I'm able to export to an external drive, but still interested in why my main drive doesn't support the export (I've tried exporting to many locations, including the top level "/"). Permissions _shouldn't_ be a problem since I've never had trouble with Unity writing to my drive before. Perhaps it's a case-sensitivity issue? Using Apple's apfs as the filesystem type.
     
    Last edited: Aug 15, 2019
  28. JohnnyJimJams_2

    JohnnyJimJams_2

    Joined:
    Jul 25, 2018
    Posts:
    1
    The problem is in the Cube.cs script. Comment out the contents of the NativeAPI class when building to Android:

    //[DllImport("__Internal")]
    //public static extern void showHostMainWindow(string lastStringColor);

    Better yet, pop some compile guards around it for IOS only. (See further down in the same script for an example of how to do the compile guard for iOS)
     
  29. SpencerIO

    SpencerIO

    Joined:
    Oct 8, 2013
    Posts:
    8
    EDIT:

    Switching to IL2CCP, and turning off Instant Run in Android Studio resolves all error and lets me use launch the AR Core example, very nice.[/QUOTE]

    ----------------
    Hello @aStrangeLoop ,

    Would you be able to share your working ARCore/Unity/NativeAndroid project? I am still getting the "No implementation found for void com.unity3d.player.UnityPlayer.nativeRestartActivityIndicator()" error even after switching to IL2CPP and turning off Instatnt Run
     
    Cinqed and zbagley like this.
  30. neosca

    neosca

    Joined:
    Jul 1, 2014
    Posts:
    11
    Not able to use Firebase in unity project. when exporting and syncing getting the following error.

    ERROR: Project with path 'Firebase' could not be found in project ':unityLibrary'.


    unity exported project structure

     
  31. flonge

    flonge

    Joined:
    Jan 25, 2014
    Posts:
    1
    Has anyone been able to deploy an arm64-v8a to Google Play, without getting an error message using Unity as a library? I'm struggling apart from this critical issue, it's been working fine for me.
     
  32. aStrangeLoop

    aStrangeLoop

    Joined:
    Feb 17, 2018
    Posts:
    8
    @SpencerIO

    Sorry for the delayed response, was on holiday.
    Here is an example of a working project (note that if you re-export the unity project, you'll have to re-do the changes to the unity's project build.gradle*) https://morkvd.stackstorage.com/s/PZ7xpobuctmPOH1

    *change the build.gradle to this:
    Code (csharp):
    1.    
    2. dependencies {
    3.         implementation fileTree(dir: 'libs', include: ['*.jar'])
    4.         compile files('libs/arcore_client.aar')
    5.         compile files('libs/unityandroidpermissions.aar')
    6.         compile files('libs/UnityARCore.aar')
    7.     }
    8.  
    I hope this helps you in any way.
     
    Last edited: Aug 27, 2019
  33. SpencerIO

    SpencerIO

    Joined:
    Oct 8, 2013
    Posts:
    8
    Hi @aStrangeLoop ,

    Thank you for trying to help me. Correct me if I'm wrong but the download looks a little platformer game rather and an ARCore app?
     
  34. aStrangeLoop

    aStrangeLoop

    Joined:
    Feb 17, 2018
    Posts:
    8
    Ooh sorry I shared the wrong file :(, Here is the correct files: https://morkvd.stackstorage.com/s/0LXjOtrZkcpfJOy it's was created in 2019.3.0a7 on windows. the AR targets are somewhere in the asset folder. I haven't touched it since before my summer break, beginning last month, so the particulars are kinda hazy, I hope it helps you.

    EDIT: ooh i noticed I used the android-ndk-r19 instead of the default one? not sure why I did it but it might be the reason I got it working.
     
  35. HardK

    HardK

    Joined:
    Nov 5, 2016
    Posts:
    7
    @aStrangeLoop this is great! I was banging my head around not being able to get ARCore to work as embedded. Thanks for sharing!

    Cheers
     
  36. jonjojo

    jonjojo

    Joined:
    Jul 29, 2014
    Posts:
    16
    Doesn't work on my Mac when identical process works on the PC, any ideas? It crashes when I click show Unity.
     
  37. SpencerIO

    SpencerIO

    Joined:
    Oct 8, 2013
    Posts:
    8
    @aStrangeLoop Awesome! thank you! Works published from my Macbook Pro
     
  38. sandeepsmartest

    sandeepsmartest

    Joined:
    Nov 7, 2012
    Posts:
    138
    Hi ,by anychance you able to figure out the issue?
     
  39. sandeepsmartest

    sandeepsmartest

    Joined:
    Nov 7, 2012
    Posts:
    138
    Hi @PavelLU , let us assume if i already have a firebase(crashlytics) sdk integrated in my android native module.Now i have Unity game as a library integrated inside android native.In this case how would firebase crashlytics work? will firebase crashlytics report crashes of my unity game with proper stacktrace to my dashboard?will firebase behave same like it behaves when i integrate inside unity stand alone android application?FYI i must have crashlytics in both my android native module and in unity game aswell.Thanks
     
  40. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,130
    FYI, @PavelLU is currently on vacation. In the meantime, please make sure to submit bug reports for issues that you encounter, ideally with minimal reproduction projects. That will significantly increase the chances of timely fixes.
     
  41. IOZO

    IOZO

    Joined:
    Jun 26, 2010
    Posts:
    55
    I'm using a single activity/multiple fragment navigation based on Android Jetpack and I want to use unity as a lib only in one fragment. It works almost as expected but my problem happens when I navigate from the unity fragment into another fragment and back from this other fragment to the unity fragment. Apparently, reloading the unity player is not possible. What should be done to allow this kind of navigation ? There was already discussions about this issue like this one https://forum.unity.com/threads/crash-with-back-button.605983/ but with unity as a library is there a better solution to address this issue ?
     
    ROBYER1 and jwSammy like this.
  42. neosca

    neosca

    Joined:
    Jul 1, 2014
    Posts:
    11
    in you settings.gradle file. try to update path for firebase folder like below:

    Code (JavaScript):
    1. include ':app' , ':unityLibrary', ':unityLibrary:Firebase'
    2. project(':unityLibrary').projectDir=new File('..\\UnityProject\\androidBuild\\unityLibrary')
    3. project(':unityLibrary:Firebase').projectDir=new File('..\\UnityProject\\androidBuild\\unityLibrary\\Firebase')
     
  43. xxxDOSxxx

    xxxDOSxxx

    Joined:
    Sep 29, 2016
    Posts:
    7
    I am Using Unity 2919.3.0b4
    photo_2019-09-24_19-30-19.jpg 1) Class generated by Unity photo_2019-09-24_19-30-22.jpg 2) Second class generated by Unity

    photo_2019-09-24_19-30-05.jpg photo_2019-09-24_19-30-14.jpg 3) Try to extend class in second step
    4) Got error error: cannot access IUnityPlayerLifecycleEvents
    class file for com.unity3d.player.IUnityPlayerLifecycleEvents not found

    When I build with 2019.3.0a3 there is no IUnityPlayerLifecicleEvents and I can acsess Override
     
    biemann likes this.
  44. agpatel0007

    agpatel0007

    Joined:
    Aug 21, 2014
    Posts:
    14
    crashed on show unity
    error :
    2019-09-25 12:46:42.853 24961-24961/? E/Unity: Failed to load 'libmain.so', the application will terminate.
    2019-09-25 12:46:42.854 24961-24961/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.unity.mynativeapp, PID: 24961
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/base.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_dependencies_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_resources_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_0_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_1_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_2_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_3_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_4_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_5_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_6_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_7_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_8_apk.apk", zip file "/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/lib/arm64, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/base.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_resources_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.unity.mynativeapp-n1OBL9UvJYapvNwaCRkAyQ==/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libmain.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
    at java.lang.System.loadLibrary(System.java:1669)
    at com.unity3d.player.UnityPlayer.<clinit>(Unknown Source:13)
    at com.unity3d.player.UnityPlayerActivity.onCreate(UnityPlayerActivity.java:40)
    at com.company.product.OverrideUnityActivity.onCreate(OverrideUnityActivity.java:20)
    at com.unity.mynativeapp.MainUnityActivity.onCreate(MainUnityActivity.java:14)
    at android.app.Activity.performCreate(Activity.java:7326)
    at android.app.Activity.performCreate(Activity.java:7317)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    2019-09-25 12:46:42.859 3275-19470/? W/ActivityManager: crash : com.unity.mynativeapp,0
     
  45. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    [!] This example is outdated.
    Since Unity version 2019.3.b4+ is out there is new Version 2 of the example, it address some issues related to this example most important one relates to unloading/quitting Unity.
     
    Last edited: Oct 4, 2019
  46. biemann

    biemann

    Joined:
    Jun 28, 2019
    Posts:
    3
    @xxxDOSxxx

    I had the same problem when updating to 2019.3b. I think the solution is to add
    Code (CSharp):
    1. implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
    to the dependencies of the app's gradle file, as described in the second version of the tutorial.
     
  47. jaigishrajan

    jaigishrajan

    Joined:
    Oct 29, 2019
    Posts:
    1
    I am getting this error when integration arcore unity as a library in native android app

    2019-10-29 17:38:19.124 16263-16263/com.unity.mynativeapp:Unity E/Unity: Failed to load 'libmain.so', the application will terminate.
    2019-10-29 17:38:19.127 16263-16263/com.unity.mynativeapp:Unity E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.unity.mynativeapp:Unity, PID: 16263
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.unity.mynativeapp-CETwBpnFzp60KqLV3S0n_A==/base.apk"],nativeLibraryDirectories=[/data/app/com.unity.mynativeapp-CETwBpnFzp60KqLV3S0n_A==/lib/x86, /data/app/com.unity.mynativeapp-CETwBpnFzp60KqLV3S0n_A==/base.apk!/lib/x86, /system/lib]]] couldn't find "libmain.so"
    at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
    at java.lang.System.loadLibrary(System.java:1669)
    at com.unity3d.player.UnityPlayer.<clinit>(Unknown Source:13)
    at com.unity3d.player.UnityPlayerActivity.onCreate(UnityPlayerActivity.java:41)
    at com.company.product.OverrideUnityActivity.onCreate(OverrideUnityActivity.java:16)
    at com.unity.mynativeapp.MainUnityActivity.onCreate(MainUnityActivity.java:16)
    at android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    2019-10-29 17:38:19.310 15700-15776/? E/s.nexuslaunche: Failed to open APK '/data/app/com.unity.mynativeapp-rhpHMw_q0oXSDqO8uBKJpg==/base.apk' I/O error
    2019-10-29 17:38:19.310 15700-15776/? E/ResourcesManager: failed to add asset path /data/app/com.unity.mynativeapp-rhpHMw_q0oXSDqO8uBKJpg==/base.apk
    2019-10-29 17:38:20.083 1816-1985/? E/IPCThreadState: binder thread pool (4 threads) starved for 723 ms
    2019-10-29 17:38:23.053 3230-3230/? E/BeaconBle: Missing BluetoothAdapter
    2019-10-29 17:38:23.544 3230-3230/? E/BeaconBle: Scan couldn't start for Places
    2019-10-29 17:38:24.160 2438-16309/? E/RequestManagerImpl: Server error
    2019-10-29 17:38:24.168 2438-16046/? E/NowController: Failed to access data from EntryProvider. ExecutionException.
    java.util.concurrent.ExecutionException: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 4
    at com.google.common.util.concurrent.d.eA(SourceFile:85)
    at com.google.common.util.concurrent.d.get(SourceFile:37)
    at com.google.common.util.concurrent.l.get(SourceFile:2)
    at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbB(SourceFile:49)
    at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbA(SourceFile:181)
    at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2)
    at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)
    at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
    at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)
    at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)
    Caused by: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 4
    at com.google.android.apps.gsa.staticplugins.nowstream.b.a.ar.az(Unknown Source:4)
    at com.google.common.util.concurrent.q.ap(SourceFile:7)
    at com.google.common.util.concurrent.p.run(SourceFile:32)
    at com.google.common.util.concurrent.bt.execute(SourceFile:3)
    at com.google.common.util.concurrent.d.b(SourceFile:275)
    at com.google.common.util.concurrent.d.a(SourceFile:229)
    at com.google.common.util.concurrent.d.aS(SourceFile:139)
    at com.google.android.apps.gsa.staticplugins.ci.j.f.de(SourceFile:3)
    at com.google.android.apps.gsa.staticplugins.ci.j.ay.Ax(SourceFile:37)
    at com.google.android.apps.gsa.staticplugins.ci.j.n.Aw(SourceFile:5)
    at com.google.android.apps.gsa.staticplugins.ci.j.q.a(SourceFile:157)
    at com.google.android.apps.gsa.staticplugins.ci.j.q.a(SourceFile:75)
    at com.google.android.apps.gsa.staticplugins.ci.j.q.apJ(SourceFile:55)
    at com.google.android.apps.gsa.sidekick.main.entry.EntriesRefreshIntentService.onHandleIntent(SourceFile:38)
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.os.HandlerThread.run(HandlerThread.java:65)
     
  48. DylanFord

    DylanFord

    Joined:
    Nov 19, 2018
    Posts:
    1
    For those who are here with "Failed to load 'libmain.so', the application will terminate." errors, check the path the following exception will outline. If it looks something like this:

    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.unity.mynativeapp:Unity, PID: 16263
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.unity.mynativeapp-CETwBpnFzp60KqLV3S0n_A==/base.apk"],nativeLibraryDirectories=[/data/app/com.unity.mynativeapp-CETwBpnFzp60KqLV3S0n_A==/lib/x86, /data/app/com.unity.mynativeapp-CETwBpnFzp60KqLV3S0n_A==/base.apk!/lib/x86, /system/lib]]] couldn't find "libmain.so"


    then it is likely that your gradle is not set to build for the same target abi as you selected in Unity. What worked for me is to copy your abiFilters line in build.gradle (Module: unityLibrary) which should be at:

    Code (CSharp):
    1. android {
    2.     defaultConfig {
    3.         ndk {
    4.             abiFilters: 'XXXX'
    5.         }
    6.    }
    7. }
    and paste it into the same relative location in your build.gradle (Module: app).

    And of course, this should really be on the new UAAL thread linked in the OP, but saw some people in this thread with that issue so wanted to give it coverage.
     
    GKiernozek likes this.
  49. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    Hello Everyone,
    We are trying to have a base native android application install multiple unity based games into the base application. The Android Dev team gets conflicts when they add multiple unity Gradle projects to their base projects.

    unityLibrary\src\main\assets\bin\Data\Managed\Metadata\global-metadata.dat
    They get a conflict here while making a build saying both modules have the same path.

    I exported an IL2CPP Arm64 Gradle project and handed it over to them. I exported using 2019.3.11b as the new structure of exporting Gradle projects is better/ closer to the android project structure which made it easier for them to implement.

    Any solution or suggestion would help. If more information is required please do let me know. I will speak to the team and update it here. I am a Game Developer in Unity and my knowledge in native android programming is fairly minimal. Any help will be appreciated thank you.
     
  50. ArpitTyagi01

    ArpitTyagi01

    Joined:
    Feb 21, 2018
    Posts:
    14
    Hello ,
    i am getting this error "DllNotFoundException: Unable to load DLL 'UnityARCore' "