AR Foundation (Android) black screen on first launch bug (IL2CPP)

Hello, I’m having issues after swapping from Mono backend to IL2CPP backend I’m finding the app prompts camera permissions but after allowing the screen stays black, if the app is closed and re-opened it then works fine, how can I remedy this so the camera works first time? (Problem doesn’t occur with Mono backend)

Thanks.

3 Likes

This used to be a problem on IL2CPP due to code stripping, but that was fixed a while ago. What version of the ARCore package do you have?

1 Like

[quote=“tdmowrer, post:2, topic: 741792, username:tdmowrer”]
This used to be a problem on IL2CPP due to code stripping, but that was fixed a while ago. What version of the ARCore package do you have?
[/quote] I’m using version 1.0.0-preview.24 of ARCore XR Plugin and 1.0.0-preview.22 of AR foundation, it says they’re both up to date in the package manager, unity version 2018.3.7f1.

I’ve also tried updating Unity to 2019.1.0f2 and updating the packages to AR Foundation 1.10 (preview.6) and ARCore to 1.00-preview.24 but I’m still having the bug.

1 Like

I have this issue as well. First launch fails after requesting camera permission.

1 Like

@tdmowrer I sent you a private message with a full logcat of this.

Do you have a link.xml in your Assets folder? If not, ARFoundation should prompt you to create one. If you do, make sure you don’t have any others elsewhere in your project as they may override this setting.

Seeing the same bug here- works fine in Mono, but when using IL2CPP first-time startup shows black screen.
There is only one link.xml file (auto-generated by AR Foundation) in my project.

Google Pixel 3 (behavior is the same on multiple devices)
Unity 2019.1.1f1
AR Foundation 1.1.0 p6
AR Core XR plugin 1.0.0 p24
ARKit XR plugin 1.0.0 p27

This appears to be a code stripping issue. The ARCorePermissionsManager implements a Java interface, so the callbacks it uses aren’t explicitly referenced by any other C# code. When managed code stripped is enabled or IL2CPP backend is used, this causes those methods to get stripped by Unity.

We can prevent this in a future release of ARFoundation, but you can workaround it now by modifying your link.xml to

<assembly fullname="Unity.XR.ARCore" preserve="all" ignoreIfMissing="1"/>

(note preserve=“all” instead of “none”)

This may cause your apk to be a bit bigger but should fix the issue.

2 Likes

Thank you, that resolved the issue!

1 Like

Has this been fixed in newer versions of AR Foundation?

It will be fixed in the next release (going through QA right now).

I have no link.xml do you have a full example of what it should contain? Including any other tags in the hierarchy.

Similar to https://github.com/Unity-Technologies/arfoundation-samples/blob/1.0/Assets/link.xml except change preserve=“none” to preserve=“all”, e.g.,

<linker>
    <assembly fullname="Unity.XR.ARCore" ignoreIfMissing="1" preserve="all"/>
</linker
1 Like

Having the same problem. Trying setting “none” to “all” now.

Hi ,
Created this AR application using AR Foundation in unity for both : ios and android.
When built for ios everything was perfectly fine . also when built the same project for android with “Mono” back-end ( development build ) , everything was good , but when I built same thing using “IL2CPP” back-end , it gives following issues:’

  1. Black Screen problem
  2. Not detecting floor properly and object gets stuck to the camera ( I have attached a screenshots for this issue )

Please help me to resolve this issue.
thanks in Advance !


1 Like

Hi
I have the same IL2CPP black screen problem / not requesting camera permission problem but with Vuforia…
Any workaround for that too?
Thanks

Having the same issue on Android too. In my case the issue is only the 2nd one, Not detecting the floor and object stuck to camera.

@sameel @Alond

I think it has to do with this issue (ARCore fails when building google play app bundle · Issue #96 · Unity-Technologies/arfoundation-samples · GitHub), turning of instant run inside android studio fixed it for me.

Inside Android Studio goto:
File → Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.

On Unity 2019.3b11 with this solution I get a compile error:

Error message

Failed running /Applications/Unity/Hub/Editor/2019.3.0b11/Unity.app/Contents/il2cpp/build/UnityLinker.exe -out=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/tempStrip” -x=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/…/platform_native_link.xml” -x=“/var/folders/nc/9blh334s75z5zxm02rn6dyg40000gn/T/tmpd1f4a6.tmp” -x=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/TypesInScenes.xml” -x=“/Users/AlexBo/Development/UnityProjects/URP/Assets/link.xml” -d=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed” --include-unity-root-assembly=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/Assembly-CSharp.dll” --include-unity-root-assembly=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/Unity.RenderPipelines.Core.Runtime.dll” --include-unity-root-assembly=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/Unity.RenderPipelines.Universal.Runtime.dll” --include-unity-root-assembly=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/UnityEngine.UI.dll” --dotnetruntime=il2cpp --dotnetprofile=unityaot --use-editor-options --include-directory=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed” --rule-set=Conservative --editor-data-file=“/Users/AlexBo/Development/UnityProjects/URP/Temp/StagingArea/assets/bin/Data/Managed/EditorToUnityLinkerData.json” --platform=Android --enable-engine-module-stripping --engine-stripping-flag=EnableUnityConnect --engine-stripping-flag=EnablePerformanceReporting --engine-stripping-flag=EnableAnalytics --engine-modules-asset-file=“/Applications/Unity/Hub/Editor/2019.3.0b11/PlaybackEngines/AndroidPlayer/Whitelists/…/modules.asset”

stdout:
Fatal error in Unity CIL Linker
System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: linker. Line 3, position 9.
at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg) [0x00029] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XmlTextReaderImpl.Throw (System.Int32 pos, System.String res, System.String arg) [0x0000c] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XmlTextReaderImpl.ThrowUnclosedElements () [0x000cc] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XmlTextReaderImpl.ParseEndElement () [0x001f7] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XmlTextReaderImpl.ParseElementContent () [0x00149] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XmlTextReaderImpl.Read () [0x00085] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XPath.XPathDocument.LoadFromReader (System.Xml.XmlReader reader, System.Xml.XmlSpace space) [0x00228] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XPath.XPathDocument…ctor (System.String uri, System.Xml.XmlSpace space) [0x00013] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at System.Xml.XPath.XPathDocument…ctor (System.String uri) [0x00000] in <1d98d70bb7d8453b80c25aa561fdecd1>:0
at Unity.Linker.Steps.Resolution.UnityResolveFromXmlStep…ctor (System.String file) [0x00000] in <98b21eac6f13437abe8e0f36445fe9d3>:0
at Unity.Linker.UnityDriver.ParseArguments (Mono.Linker.Pipeline p, Unity.Linker.UnityLinkContext context, System.Collections.ArrayList custom_steps, Mono.Linker.I18nAssemblies& assemblies) [0x001d1] in <98b21eac6f13437abe8e0f36445fe9d3>:0
at Unity.Linker.UnityDriver.Run () [0x0001b] in <98b21eac6f13437abe8e0f36445fe9d3>:0
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling () [0x00007] in <98b21eac6f13437abe8e0f36445fe9d3>:0
at Unity.Linker.UnityDriver.RunDriver () [0x00002] in <98b21eac6f13437abe8e0f36445fe9d3>:0
stderr:

UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:126)
UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action1) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:71) UnityEditorInternal.AssemblyStripper:RunAssemblyLinker(IEnumerable1, String&, String&, String, String) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:166)
UnityEditorInternal.AssemblyStripper:StripAssembliesTo(String, String&, String&, IEnumerable1, UnityLinkerRunInformation) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:159) UnityEditorInternal.AssemblyStripper:RunAssemblyStripper(UnityLinkerRunInformation) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:301) UnityEditorInternal.AssemblyStripper:StripAssemblies(String, BaseUnityLinkerPlatformProvider, IIl2CppPlatformProvider, RuntimeClassRegistry, ManagedStrippingLevel) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:178) UnityEditorInternal.IL2CPPBuilder:Run() (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:327) UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action1, RuntimeClassRegistry) (at /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:65)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at /Users/builduser/buildslave/unity/build/Editor/Mono/EditorApplication.cs:442)