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. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    This document explains how to include Unity as a Library into standard Android application through Activity. You can read more about Unity as a Library.

    This example address Version 1 issues of example, most important one relates to unloading/quitting Unity.

    Pre Requirements:
    • Android Studio 3.4.2+
    • Unity version 2019.3.0b4+

    1. Get source

    • Clone or Download GitHub repo uaal-example. It includes:
      image9.png
      • Unityproject - this is a simple demo project made with Unity which will be integrated to the standard Android application. OverrideUnityActivity class in Assets/Plugins/Android extends UnityPlayerActivity
      • NativeAndroidApp - this is the Basic Activity application from Android Studio templates where Unity project will be integrated. It has a simple UI, MainUnityActivity, which extends OverrideUnityActivity, and is prepared to start MainUnityActivity with an Intent
    2. Generate gradle project for Android platform
    • Open UnityProject in Unity Editor
    • Go to Build Settings window (Menu / File / Build Settings)
      • Select and switch to Android Platform
      • Select option “Export Project” image6.png
    • Export UnityProject to androidBuild folder, the folder structure should look like this: image11.png
     
    Last edited: Nov 5, 2019
  2. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    3. Add Unity Library module to NativeAndroidApp
    Do the following to add the exported androidBuild/unityLibrary module to the NativeAndroidApp gradle project in Android Studio:
    • Open NativeAndroidApp in Android Studio
    • Open settings.gradle file
      • Add a new project pointing to unityLibrary module at the end of the file:
    Code (CSharp):
    1. include ':unityLibrary'
    2. project(':unityLibrary').projectDir=new File('..\\UnityProject\\androidBuild\\unityLibrary')
    image5.png
    • Open build.gradle(Module: app) file
      • Add the following in dependencies{ block
    Code (CSharp):
    1. implementation project(':unityLibrary')
    2. implementation fileTree(dir: project(':unityLibrary').getProjectDir().toString() + ('\\libs'), include: ['*.jar'])
    image8.png
    • Open build.gradle(Project: NativeAndroidApp) file
      • Add the following in allprojects{repositories{ block
    Code (CSharp):
    1. flatDir {
    2.     dirs "${project(':unityLibrary').projectDir}/libs"
    3. }
    image1.png

    • Click Sync Now to do a project sync since gradle files have been modified image2.png
    • If everything succeeds, you should see unityLibrary module added in Android view image7.png
     
    nadin1223 likes this.
  3. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    Project is ready
    Everything is ready to build, run and debug: image4.png

    If everything succeeded, at this point you should be able to run NativeAndroidApp: howItLooks.jpg
    Important note:
    • Unity is running in another process android: process=":Unity" (AndroidManifest.xml at app module)
    • After installation there will be two icons added on the device. To leave only the icon of the main activity, remove <intent-filter>...</intent-filter> from the AndroidManifest.xml in unityLibrary
    • (Optional) We found some Android 7.* devices set frontOfTask to wrong state for activities as a result when finishing/quitting Unity activity whole task goes to background instead of bringing back Main activity. Next workaround keeps expected behavior: add to MainUnityActivity.java from NativeAndroidApp
    Code (CSharp):
    1. @Override public void onUnityPlayerQuitted() { showMainActivity(""); finish(); }
    Full Project
    If you have issues following integration steps you can try out fully prepared project ready to build and deploy: Download & Uncompress Full Uaal Example Android project, then open NativeAndroidApp in Android Studio.
     
    Last edited: Sep 27, 2019
  4. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Looks like the way the unloading/quitting issues were addressed is by having Unity run in a separate process and explicitly killing it.

    This was the workaround that my team had investigated but ultimately our client is unwilling to operate with the JVM split into multiple processes. This is because they use Android UI elements over the Unity view that need to access the objects from the app's memory. To continue doing this, they would need to replicate their main process memory in the Unity process.

    Ultimately we found other workarounds to use Unity in the same process but workarounds are not what we like to ship in production code. Will there be any solution (like tightening up Unity's shut-down sequence) for apps that cannot be split?
     
  5. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    IUnityPlayerLifecycleEvents introduced since 2019.3.b4+ provides easy way to react to two important lifecycle events of Unity Player:
    • Unload - IUnityPlayerLifecycleEvents.onUnityPlayerUnloaded will be called when unity player will be unloaded though Application.Unload or UnityPlayer.unload(). (UnityPlayer in unloaded/paused state atm.)
    • Quit - IUnityPlayerLifecycleEvents.onUnityPlayerQuitted is called when Unity player did quit. Please note process where unity was running will be killed after this call.
    You can pass instance of IUnityPlayerLifecycleEvents to UnityPlayer constructor or override methods in subclasses of UnityPlayer or UnityPlayerActivity

    @btristan you can try keep activity in same process and relay on Unload
     
    Last edited: Sep 30, 2019
  6. zbagley

    zbagley

    Joined:
    May 23, 2019
    Posts:
    3
    @PavelLU Would you be able to provide the steps required to make a 2019.3.b1-3 project compliant with b4+ build?
     
  7. HedwigMendix

    HedwigMendix

    Joined:
    Sep 2, 2019
    Posts:
    4
    This all is exactly what I was looking for! I'm working on making an Android AR function into my native android app using Unity as a Library. However, when I import the ARCore package in the example app it immediately crashes. Do I need to enable anything in the standard Android app provided to get AR working?

    Code (JavaScript):
    1. 2019-10-01 13:07:53.189 10682-10682/com.unity.mynativeapp:Unity E/AndroidRuntime: FATAL EXCEPTION: main
    2.     Process: com.unity.mynativeapp:Unity, PID: 10682
    3.     java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.unity.mynativeapp-6EhPtngHs603UwkTWPvsew==/base.apk"],nativeLibraryDirectories=[/data/app/com.unity.mynativeapp-6EhPtngHs603UwkTWPvsew==/lib/arm64, /data/app/com.unity.mynativeapp-6EhPtngHs603UwkTWPvsew==/base.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libmain.so"
    4.        at java.lang.Runtime.loadLibrary0(Runtime.java:1012)
    5.        at java.lang.System.loadLibrary(System.java:1669)
    6.        at com.unity3d.player.UnityPlayer.<clinit>(Unknown Source:13)
    7.        at com.unity3d.player.UnityPlayerActivity.onCreate(UnityPlayerActivity.java:41)
    8.        at com.company.product.OverrideUnityActivity.onCreate(OverrideUnityActivity.java:16)
    9.        at com.unity.mynativeapp.MainUnityActivity.onCreate(MainUnityActivity.java:16)
    10.        at android.app.Activity.performCreate(Activity.java:7326)
    11.        at android.app.Activity.performCreate(Activity.java:7317)
    12.        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
    13.        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
    14.        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
    15.        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    16.        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    17.        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    18.        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
    19.        at android.os.Handler.dispatchMessage(Handler.java:106)
    20.        at android.os.Looper.loop(Looper.java:214)
    21.        at android.app.ActivityThread.main(ActivityThread.java:6986)
    22.        at java.lang.reflect.Method.invoke(Native Method)
    23.        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    24.        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)
    I tried with both AR Foundation + ARCore through package manager and the ARCore provided as a .unitypackage. Both make the unity part of the app crash instantly, even when I'm not using anything of it yet. Just having it in htere makes it crash.
     
    Last edited: Oct 2, 2019
  8. brunno159

    brunno159

    Joined:
    Oct 24, 2014
    Posts:
    23
    I'm getting the same error ...
     
  9. HedwigMendix

    HedwigMendix

    Joined:
    Sep 2, 2019
    Posts:
    4
    I got it working! I had to enable Player > Configuration > Scripting Backend to IL2CPP and Player > Configuration > Target Architectures > ARM64.
     
    xwonder and charlesb_rm like this.
  10. Ofreyre

    Ofreyre

    Joined:
    Jul 17, 2013
    Posts:
    28
    Using Unity project in this thread with Unity2019.3.0b5, I could compile it to Android, IL2CPP, ARM64.

    But when I include Vuforia to the project I get compilation errors:

    IL2CPP error for type 'UnityEngine.Experimental.Rendering.RenderPipeline' in assembly 'D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\UnityEngine.dll'
    Additional information: Exception has been thrown by the target of an invocation.


    Failed running C:\Program Files\Unity\Hub\Editor\2019.3.0b5\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="ARM64" --configuration="Release" --outputpath="D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Native\arm64-v8a\libil2cpp.so" --cachedirectory="D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Assets\..\Library\il2cpp_android_arm64-v8a/il2cpp_cache" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include" --tool-chain-path="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" --profiler-report --map-file-parser="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory=D:/Public/AndroidStudio/HoodooSDKtest/UnityProject/Temp/StagingArea/assets/bin/Data/Managed --generatedcppdir=D:/Public/AndroidStudio/HoodooSDKtest/UnityProject/Temp/StagingArea/Il2Cpp/il2cppOutput

    stdout:
    IL2CPP error for type 'UnityEngine.Experimental.Rendering.RenderPipeline' in assembly 'D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\UnityEngine.dll'
    Additional information: Exception has been thrown by the target of an invocation.
    il2cpp.exe didn't catch exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.ErrorInformation.set_Method(MethodDefinition value)
    at Unity.IL2CPP.GenericsCollection.GenericContextFreeVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(EventDefinition eventDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.CollectPerAssembly(AssemblyDefinition assembly)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.MergeCollections(IEnumerable`1 collections)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    at il2cpp.Program.Main(String[] args)
    stderr:

    Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.ErrorInformation.set_Method(MethodDefinition value)
    at Unity.IL2CPP.GenericsCollection.GenericContextFreeVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(EventDefinition eventDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.CollectPerAssembly(AssemblyDefinition assembly)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.MergeCollections(IEnumerable`1 collections)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    at il2cpp.Program.Main(String[] args)

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1)
    UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String)
    UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(Il2CppBuildPipelineData, String, String, Boolean)
    UnityEditorInternal.IL2CPPBuilder:Run()
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    Exception: C:\Program Files\Unity\Hub\Editor\2019.3.0b5\Editor\Data\il2cpp/build/il2cpp.exe did not run properly!
    UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo, System.String workingDirectory) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPBuilder.Run () (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditor.Android.PostProcessor.Tasks.RunIl2Cpp.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    Build completed with a result of 'Failed'
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00275] in <52c46852ed4749ed926125cda2005635>:0
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <52c46852ed4749ed926125cda2005635>:0
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  11. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    Hi, I have issues trying to build a Android build, tried it on emulator and on phone. But it always crashes when I clicked Open in Unity. The thing is there is no error at all in the Android Studio's logcat and build logs.

    Anyone knows what's happening? It even happens with the full build that is "completed"
     
    ferryjufri likes this.
  12. PavelLU

    PavelLU

    Unity Technologies

    Joined:
    Feb 23, 2017
    Posts:
    107
    Can you please check if you can Build & Run your project with Vuforia to phone directly from Unity, (don't do any integration to native steps)
     
  13. brunno159

    brunno159

    Joined:
    Oct 24, 2014
    Posts:
    23
    Can someone check if unity default videoplayer component plays when added to ar when unity is built as a library? Ive just ported my unity app as a library( my app uses a plane to play a video when a marker is detected). If i build it as a unity app and install it works ok. But if i include as library the plane shows but not video or audio is played...
     
    Last edited: Oct 4, 2019
    Support_Tapptic and raphaelnew like this.
  14. Ofreyre

    Ofreyre

    Joined:
    Jul 17, 2013
    Posts:
    28
    Same error when building an apk ( IL2CPP, .net 4 or 2, ARM64):

    IL2CPP error for type 'UnityEngine.Experimental.Rendering.RenderPipeline' in assembly 'D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\UnityEngine.dll'
    Additional information: Exception has been thrown by the target of an invocation.


    Failed running C:\Program Files\Unity\Hub\Editor\2019.3.0b5\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="ARM64" --configuration="Release" --outputpath="D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Native\arm64-v8a\libil2cpp.so" --cachedirectory="D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Assets\..\Library\il2cpp_android_arm64-v8a/il2cpp_cache" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include" --tool-chain-path="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" --profiler-report --map-file-parser="C:/Program Files/Unity/Hub/Editor/2019.3.0b5/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory=D:/Public/AndroidStudio/HoodooSDKtest/UnityProject/Temp/StagingArea/assets/bin/Data/Managed --generatedcppdir=D:/Public/AndroidStudio/HoodooSDKtest/UnityProject/Temp/StagingArea/Il2Cpp/il2cppOutput

    stdout:
    IL2CPP error for type 'UnityEngine.Experimental.Rendering.RenderPipeline' in assembly 'D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\UnityEngine.dll'
    Additional information: Exception has been thrown by the target of an invocation.
    il2cpp.exe didn't catch exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.ErrorInformation.set_Method(MethodDefinition value)
    at Unity.IL2CPP.GenericsCollection.GenericContextFreeVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(EventDefinition eventDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.CollectPerAssembly(AssemblyDefinition assembly)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.MergeCollections(IEnumerable`1 collections)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    at il2cpp.Program.Main(String[] args)
    stderr:

    Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.ErrorInformation.set_Method(MethodDefinition value)
    at Unity.IL2CPP.GenericsCollection.GenericContextFreeVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(EventDefinition eventDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.CollectPerAssembly(AssemblyDefinition assembly)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.MergeCollections(IEnumerable`1 collections)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    at il2cpp.Program.Main(String[] args)

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1)
    UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String)
    UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(Il2CppBuildPipelineData, String, String, Boolean)
    UnityEditorInternal.IL2CPPBuilder:Run()
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    Exception: C:\Program Files\Unity\Hub\Editor\2019.3.0b5\Editor\Data\il2cpp/build/il2cpp.exe did not run properly!
    UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo, System.String workingDirectory) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPBuilder.Run () (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEditor.Android.PostProcessor.Tasks.RunIl2Cpp.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <7a3206746c744c65a3137ccfd4678266>:0)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <52c46852ed4749ed926125cda2005635>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    Build completed with a result of 'Failed'
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00275] in <52c46852ed4749ed926125cda2005635>:0
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <52c46852ed4749ed926125cda2005635>:0
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
    Last edited: Oct 4, 2019
  15. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    Is there any settings that the guide above is missing? I've followed the guide step by step and I've checked it multiple times and still it crashes on clicking the Open Unity within the app.
     
  16. hiachrism

    hiachrism

    Joined:
    Aug 16, 2019
    Posts:
    4
    Seems like there may be a step missing around how you incorporate the OverrideUnityActivity into the native app. The example implementation works but I can't discern a difference between that and my custom attempt.
     
    john_goren likes this.
  17. hiachrism

    hiachrism

    Joined:
    Aug 16, 2019
    Posts:
    4
    The example project extends OverrideUnityActivity with MainUnityActivity but MainUnityActivity isn't mentioned in the walkthrough. Some sort of linking/namespacing issue? Hope this helps.
     
    john_goren and Sujith_Nair like this.
  18. charmcrescini

    charmcrescini

    Joined:
    Sep 9, 2019
    Posts:
    18
    I
    I applied AR Foundation. My app crushes when I open the Unity window in native android app. Does anyone know the reason why?
     
  19. charmcrescini

    charmcrescini

    Joined:
    Sep 9, 2019
    Posts:
    18
    same issue. I just applied AR foundation to the example project they have and build it again. The unity window crashes in native app.
     
  20. HedwigMendix

    HedwigMendix

    Joined:
    Sep 2, 2019
    Posts:
    4
    Did you enable Player > Configuration > Scripting Backend to IL2CPP and Player > Configuration > Target Architectures > ARM64 ?
     
  21. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    @HedwigMendix I tried to apply the settings and built it again. But it doesn't work still. Still crashes without any errors.
     
  22. HedwigMendix

    HedwigMendix

    Joined:
    Sep 2, 2019
    Posts:
    4
    I'm also on the b5 version, that could be it?
     
  23. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    I managed to get it to work by turning off Engine Stripping in the configurations. This step is not stated in the tutorial above.
     
    john_goren likes this.
  24. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    @charmcrescini how did you manage to get ARFoundation to run? I tried to export the ARFoundation project as a test to Android Studio and followed the above flow. But these few lines that presumably is added by Unity to handle AR functionality is giving Unresolved depencies errors in Android Studio:

    implementation(name: 'arcore_client', ext:'aar')
    implementation(name: 'ARPresto', ext:'aar')
    implementation(name: 'unityandroidpermissions', ext:'aar')
    implementation(name: 'UnityARCore', ext:'aar')
     
    carlos_gerardo likes this.
  25. Vipatronon

    Vipatronon

    Joined:
    Aug 23, 2016
    Posts:
    11
    Tried here with two different versions: 2019.3.0b5 and 2019.3.07. Same error under same conditions, even with a blank project just with Vuforia...

     
    Ofreyre likes this.
  26. LuizBeenoculus

    LuizBeenoculus

    Joined:
    May 17, 2018
    Posts:
    11
    This work with Flutter???
    There is a way to trade data between the "parent native app" and the unity process?
     
  27. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    You can use JNI but my team has found that socket-based messaging is much faster.
     
    Last edited: Oct 17, 2019
    LuizBeenoculus likes this.
  28. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    Anyone managed to make ARFoundation or Vuforia work with Android Studio with Unity as a Library?

    Thanks in advanced for the help.
     
    john_goren likes this.
  29. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    Hello Everyone, I am new to native android programming. I have been able to achieve a similar feature where we make AAR file from the Unity Exported project and the native android app can launch it with a button press. I have been trying this new library method but getting an error on
    MainUnityActivity.class (Unresolved symbol). I have attached the screenshots of the code that I have modified. Not sure what I am doing wrong here.
     

    Attached Files:

  30. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    Hi all, I have a fundamental question. So far this Unity as a Library function allows Android Studio to run Unity based programs as a sort of a extension. But essentially this means it's running 2 different apps - 1 Android Studio and the other Unity.
    Is there a way to access Unity's ARFoundation functions in Android Studio to implement AR functionality using Android Studio completely and using Unity's library just to access the apis.

    Would appreciate if there is a answer for it.
     
    jeffwiy likes this.
  31. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    AFAIK the unity APIs are not exposed to Java.

    However, you can write your own Java layer which sends messages to a .Net receiver (that you also need to write) which then calls the Unity functions you desire.
     
  32. kl20

    kl20

    Joined:
    Feb 18, 2017
    Posts:
    5
    Has anyone experience any performance issues with the beta and second version of these instructions? In our project loading a scene can sometimes take 5-10 seconds which didn't happen before with the alpha.

    Profiling the app it seems like Unity is stuck on a method called "UpdatePreloading"

    I found by removing the majority of scenes in our project, the problem went away - it seems to be that the load time becomes worse with an increase in the number of scenes in our project. This isn't the case when I added a lot of empty scenes, so it seems to be something about the other scenes referencing assets, which I don't understand.
     
    Last edited: Oct 21, 2019
  33. LuizBeenoculus

    LuizBeenoculus

    Joined:
    May 17, 2018
    Posts:
    11
    Socket-base = a kind of internal network?
     
  34. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    Yes. We have a server on one end and a client on the other, both using a specific port on localhost.
     
  35. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    @btristan Do you have any examples regarding the .NET layer? I'm relatively new to .NET
     
  36. btristan

    btristan

    Joined:
    Oct 15, 2018
    Posts:
    95
    It depends on where you want your server to be. (you could also write your system to have the ability to start a server on either side, for more flexibility - which is what my team did)

    If you want to have your server be on the .NET side: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=netframework-4.7.1

    Here is the .NET client: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient?view=netframework-4.7.1

    Java has similar systems. Here is the server: https://docs.oracle.com/javase/8/docs/api/java/net/ServerSocket.html

    And here is the Java client: https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html

    The servers both operate the same way in that any new connection will spin off a client to talk to the remote. This is nice because then the code to talk to each side is essentially the same. (just in different languages)

    I do all this off the main thread. (I don't want to impact the frame rate) I have wrapped each client in a class that can accept messages and puts them into a blocking queue. When the message is in the queue a thread takes the message, serializes it, and writes the bytes into the client which will send it to the remote. When a message is received by a client, I have it put into another blocking queue which is processed on yet another thread. After the message is deserialized it is sent to a message dispatcher which decides where the message should go.
     
    PavelLU likes this.
  37. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    @btristan Wow, thank you so much for the super comprehensive answer. Will try to implement on my end; fingers crossed! Once again, thank you!
     
    btristan likes this.
  38. Ofreyre

    Ofreyre

    Joined:
    Jul 17, 2013
    Posts:
    28
    Solved!

    Using Unity 2019.3.0b8 (maybe it works with previous versions). I updated Vuforia to 8.5.8.

    Exported gladle project, integrated to native app, and debugged on Samsung S8.


    Using Unity project in this thread with Unity2019.3.0b8, I could compile it to Android, IL2CPP, ARM64.

    But when I include Vuforia 8.3.8 to the project I get compilation errors for exporting project and compiling APK:

    IL2CPP error for type 'UnityEngine.Experimental.Rendering.RenderPipeline' in assembly 'D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\UnityEngine.dll'
    Additional information: Exception has been thrown by the target of an invocation.

    -------------------------------------------------------------------------------------------

    Failed running C:\Program Files\Unity\Hub\Editor\2019.3.0b8\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="ARM64" --configuration="Release" --outputpath="D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Native\arm64-v8a\libil2cpp.so" --cachedirectory="D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Assets\..\Library\il2cpp_android_arm64-v8a/il2cpp_cache" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.3.0b8/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.3.0b8/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include" --tool-chain-path="C:/Program Files/Unity/Hub/Editor/2019.3.0b8/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" --profiler-report --map-file-parser="C:/Program Files/Unity/Hub/Editor/2019.3.0b8/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory=D:/Public/AndroidStudio/HoodooSDKtest/UnityProject/Temp/StagingArea/assets/bin/Data/Managed --generatedcppdir=D:/Public/AndroidStudio/HoodooSDKtest/UnityProject/Temp/StagingArea/Il2Cpp/il2cppOutput

    stdout:
    IL2CPP error for type 'UnityEngine.Experimental.Rendering.RenderPipeline' in assembly 'D:\Public\AndroidStudio\HoodooSDKtest\UnityProject\Temp\StagingArea\assets\bin\Data\Managed\UnityEngine.dll'
    Additional information: Exception has been thrown by the target of an invocation.
    il2cpp.exe didn't catch exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.ErrorInformation.set_Method(MethodDefinition value)
    at Unity.IL2CPP.GenericsCollection.GenericContextFreeVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(EventDefinition eventDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.CollectPerAssembly(AssemblyDefinition assembly)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.MergeCollections(IEnumerable`1 collections)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    at il2cpp.Program.Main(String[] args)
    stderr:

    Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at Unity.IL2CPP.ErrorInformation.set_Method(MethodDefinition value)
    at Unity.IL2CPP.GenericsCollection.GenericContextFreeVisitor.Visit(MethodDefinition methodDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(EventDefinition eventDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(TypeDefinition typeDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(ModuleDefinition moduleDefinition, Context context)
    at Unity.Cecil.Visitor.Visitor.Visit(AssemblyDefinition assemblyDefinition, Context context)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at Unity.Cecil.Visitor.Visitor.Visit[T](T node, Context context)
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.CollectPerAssembly(AssemblyDefinition assembly)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at Unity.IL2CPP.GenericsCollection.GenericsCollector.MergeCollections(IEnumerable`1 collections)
    at Unity.IL2CPP.AssemblyConverter.Apply()
    at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(IEnumerable`1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder, NPath executableAssembiesFolder, NPath monoLibFolder, NPath monoEtcFolder, NPath[] searchDirectories, String entryAssemblyName, NPath[] extraTypesFiles)
    at il2cpp.Program.DoRun(String[] args, List`1 foundAssemblies)
    at il2cpp.Program.Run(String[] args, Boolean setInvariantCulture)
    at il2cpp.Program.Main(String[] args)

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1)
    UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String)
    UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(Il2CppBuildPipelineData, String, String, Boolean)
    UnityEditorInternal.IL2CPPBuilder:Run()
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    -------------------------------------------------------------------------------------------

    Exception: C:\Program Files\Unity\Hub\Editor\2019.3.0b8\Editor\Data\il2cpp/build/il2cpp.exe did not run properly!
    UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo, System.String workingDirectory) (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEditorInternal.IL2CPPBuilder.Run () (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEditor.Android.PostProcessor.Tasks.RunIl2Cpp.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <0f43558419464e7998bab34f19e34e61>:0)
    UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <0f43558419464e7998bab34f19e34e61>:0)
    UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <0f43558419464e7998bab34f19e34e61>:0)
    UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <0f43558419464e7998bab34f19e34e61>:0)
    UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <9f61046f43c743d99486c2fccce7b774>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    -------------------------------------------------------------------------------------------

    Build completed with a result of 'Failed'
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    -------------------------------------------------------------------------------------------

    UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00275] in <9f61046f43c743d99486c2fccce7b774>:0
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <9f61046f43c743d99486c2fccce7b774>:0
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  39. Kundragg

    Kundragg

    Joined:
    Oct 25, 2019
    Posts:
    1
    Hi,
    With this example I understand that you can get unity values to the native app (box color in this example) but is the opposite possible? is it possible to get values from the native application in the unity app ?
     
    nallaperumal likes this.
  40. Redbeanmouse

    Redbeanmouse

    Joined:
    Nov 2, 2016
    Posts:
    7
    Does anyone have same issue as below?
    * unity 2019.3.0b8
    * android studio
    * IL2CPP, arm64

    * in android studio, I run the app, that makes same icon twice as i attached.
    left icon works fine, right icon shows error msg, just quit itself.

    I would like to have a solution or tips even small one

    Thanks
     

    Attached Files:

  41. GSO_GT

    GSO_GT

    Joined:
    Aug 30, 2019
    Posts:
    17
    @Redbeanmouse maybe you missed out this line in the tutorial:

    After installation there will be two icons added on the device. To leave only the icon of the main activity, remove <intent-filter>...</intent-filter> from the AndroidManifest.xml in unityLibrary
     
    jeffwiy and Redbeanmouse like this.
  42. Redbeanmouse

    Redbeanmouse

    Joined:
    Nov 2, 2016
    Posts:
    7
    oops I did not pay attention to the important message...
    • To leave only the icon of the main activity, remove <intent-filter>...</intent-filter> from the AndroidManifest.xml in unityLibrary
     
  43. Redbeanmouse

    Redbeanmouse

    Joined:
    Nov 2, 2016
    Posts:
    7
    Thx... I found my mistake!!
     
  44. xwonder

    xwonder

    Joined:
    Jun 18, 2018
    Posts:
    10
    Hey,


    I'm experiencing an issue where the library works and behaves as it should on the PC where the library was first implemented but does not work when built from a version of the project pulled from Git on another PC. When the project is transferred from one PC to the other by USB the library works as it should. Any idea why this is happening? I am using an unaltered version of the .gitignore provided by Android Studio (posted below).


    Code (CSharp):
    1. # Created by https://www.gitignore.io/api/android,intellij
    2. # Edit at https://www.gitignore.io/?templates=android,intellij
    3.  
    4. ### Android ###
    5. # Built application files
    6. *.apk
    7. *.ap_
    8. *.aab
    9.  
    10. # Files for the ART/Dalvik VM
    11. *.dex
    12.  
    13. # Java class files
    14. *.class
    15.  
    16. # Generated files
    17. bin/
    18. gen/
    19. out/
    20.  
    21. # Gradle files
    22. .gradle/
    23. build/
    24.  
    25. # Local configuration file (sdk path, etc)
    26. local.properties
    27.  
    28. # Proguard folder generated by Eclipse
    29. proguard/
    30.  
    31. # Log Files
    32. *.log
    33.  
    34. # Android Studio Navigation editor temp files
    35. .navigation/
    36.  
    37. # Android Studio captures folder
    38. captures/
    39.  
    40. # IntelliJ
    41. *.iml
    42. .idea/workspace.xml
    43. .idea/tasks.xml
    44. .idea/gradle.xml
    45. .idea/assetWizardSettings.xml
    46. .idea/dictionaries
    47. .idea/libraries
    48. .idea/caches
    49. # Android Studio 3 in .gitignore file.
    50. .idea/caches/build_file_checksums.ser
    51. .idea/modules.xml
    52.  
    53. # Keystore files
    54. # Uncomment the following lines if you do not want to check your keystore files in.
    55. #*.jks
    56. #*.keystore
    57.  
    58. # External native build folder generated in Android Studio 2.2 and later
    59. .externalNativeBuild
    60.  
    61. # Google Services (e.g. APIs or Firebase)
    62. # google-services.json
    63.  
    64. # Freeline
    65. freeline.py
    66. freeline/
    67. freeline_project_description.json
    68.  
    69. # fastlane
    70. fastlane/report.xml
    71. fastlane/Preview.html
    72. fastlane/screenshots
    73. fastlane/test_output
    74. fastlane/readme.md
    75.  
    76. # Version control
    77. vcs.xml
    78.  
    79. # lint
    80. lint/intermediates/
    81. lint/generated/
    82. lint/outputs/
    83. lint/tmp/
    84. # lint/reports/
    85.  
    86. ### Android Patch ###
    87. gen-external-apklibs
    88. output.json
    89.  
    90. ### Intellij ###
    91. # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
    92. # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
    93.  
    94. # User-specific stuff
    95. .idea/**/workspace.xml
    96. .idea/**/tasks.xml
    97. .idea/**/usage.statistics.xml
    98. .idea/**/dictionaries
    99. .idea/**/shelf
    100.  
    101. # Generated files
    102. .idea/**/contentModel.xml
    103.  
    104. # Sensitive or high-churn files
    105. .idea/**/dataSources/
    106. .idea/**/dataSources.ids
    107. .idea/**/dataSources.local.xml
    108. .idea/**/sqlDataSources.xml
    109. .idea/**/dynamic.xml
    110. .idea/**/uiDesigner.xml
    111. .idea/**/dbnavigator.xml
    112.  
    113. # Gradle
    114. .idea/**/gradle.xml
    115. .idea/**/libraries
    116.  
    117. # Gradle and Maven with auto-import
    118. # When using Gradle or Maven with auto-import, you should exclude module files,
    119. # since they will be recreated, and may cause churn.  Uncomment if using
    120. # auto-import.
    121. # .idea/modules.xml
    122. # .idea/*.iml
    123. # .idea/modules
    124.  
    125. # CMake
    126. cmake-build-*/
    127.  
    128. # Mongo Explorer plugin
    129. .idea/**/mongoSettings.xml
    130.  
    131. # File-based project format
    132. *.iws
    133.  
    134. # IntelliJ
    135.  
    136. # mpeltonen/sbt-idea plugin
    137. .idea_modules/
    138.  
    139. # JIRA plugin
    140. atlassian-ide-plugin.xml
    141.  
    142. # Cursive Clojure plugin
    143. .idea/replstate.xml
    144.  
    145. # Crashlytics plugin (for Android Studio and IntelliJ)
    146. com_crashlytics_export_strings.xml
    147. crashlytics.properties
    148. crashlytics-build.properties
    149. fabric.properties
    150.  
    151. # Editor-based Rest Client
    152. .idea/httpRequests
    153.  
    154. # Android studio 3.1+ serialized cache file
    155.  
    156. # JetBrains templates
    157. **___jb_tmp___
    158.  
    159. ### Intellij Patch ###
    160. # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
    161.  
    162. #*.iml
    163. # modules.xml
    164. # .idea/misc.xml
    165. # *.ipr
    166.  
    167. # Sonarlint plugin
    168. .idea/sonarlint
    169.  
    170. # End of https://www.gitignore.io/api/android,intellij
     
  45. GKiernozek

    GKiernozek

    Joined:
    Nov 16, 2013
    Posts:
    39
    Hello, I have an issue - when I try to launch Unity Intent, immediately after I press "show unity" button, whole app crashes. Any tips for this? I'm simply building new example app
    I'm using Unity 2019.3.0b10

    EDIT: If anyone has this issue roll back to Android Studio 3.4.2, as Android Studio 3.5 won't work
     
    Last edited: Nov 13, 2019
  46. Hagalaz

    Hagalaz

    Joined:
    Nov 25, 2017
    Posts:
    1
    Hi,

    Is there any way to send a message from Unity as a library to Android ? The same way that we can send message from Android to Unity.

    Thanks.
     
    nallaperumal and loudo like this.
  47. CyRaid

    CyRaid

    Joined:
    Mar 31, 2015
    Posts:
    134
    Is rendering to only part of the screen implemented? I mean, one could probably use a render texture, then bank on GLES2/3 (and not use Vulkan) and manually take the texture and use it in a native Android App.. Setting a 'device viewport' somewhere in .NET code would be really handy.

    An even better way would be to manually render to a bounds / region.
     
    Last edited: Nov 21, 2019
  48. xwonder

    xwonder

    Joined:
    Jun 18, 2018
    Posts:
    10
    There is a way!

    Example:
    Code (CSharp):
    1. // Unity player (C#):
    2. AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    3.  
    4. AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    5.  
    6. activity.Call("gameFinished", gameIsFinished);
    Here I'm calling the method gameFinished() which I defined in my MainUnityPlayer activity on the Android side and passing the gameIsFinished string as its parameter. I'm sure there's some documentation about it if you look for it.
     
    nallaperumal, Hagalaz and loudo like this.
  49. GKiernozek

    GKiernozek

    Joined:
    Nov 16, 2013
    Posts:
    39
    I've finally managed to run ARFoundation in UaaL :) Below something which can help you on the way after buiding with IL2CPP option.

    Info from thread of version 1 of this tutorial of how to overcome libmain.so error by @DylanFord

     
    Last edited: Nov 19, 2019
    ByteflowXxX likes this.
  50. 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. Any help will be appreciated thank you.
     
    Last edited: Nov 21, 2019
    GKiernozek likes this.