Asset Bundle code stripping / link.xml not working

Hello,

I’m currently working on a project for WebGL build, working with assets bundle. When I make my build for WebGL I get the following errors :

Error on mozzilla :

An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was:
uncaught exception: abort(70) at jsStackTrace (VisionneuseWebGL.asm.framework.unityweb:1218:12)
stackTrace (VisionneuseWebGL.asm.framework.unityweb:1232:11)
abort (VisionneuseWebGL.asm.framework.unityweb:453801:43)
nullFunc_vii (VisionneuseWebGL.asm.framework.unityweb:28536:2)
b70 (blob:2955384:1)
mftCall_vii (blob:2851775:1)
__ZL15CloneObjectImplP6ObjectP9TransformR10vector_mapIiiNSt3__24lessIiEE13stl_allocatorINS4_4pairIiiEEL18MemLabelIdentifier1ELi16EEE (blob:758505:1)
__Z17InstantiateObjectR6ObjectRK8Vector3fRK11Quaternionf (blob:1871450:1)
__Z54Object_CUSTOM_INTERNAL_CALL_Internal_InstantiateSingleP12Il2CppObjectRK8Vector3fRK11Quaternionf (blob:2549506:1)
ce6e49761d2c31df7859c6e83cd6c075 [UnityLoader.ce6e49761d2c31df7859c6e83cd6c075/asm.__Z54Object_CUSTOM_INTERNAL_CALL_Internal_InstantiateSingleP12Il2CppObjectRK8Vector3fRK11Quaternionf] (VisionneuseWebGL.asm.framework.unityweb:347924:9)
ftCall_iiii (blob:4941:10)
mftCall_iiii (blob:505295:9)
_Object_INTERNAL_CALL_Internal_InstantiateSingle_m937318366 (blob:483688:9)
_Object_Internal_InstantiateSingle_m152726869 (blob:419824:9)
_Object_Instantiate_m3128801945 (blob:220306:8)
_Object_Instantiate_TisRuntimeObject_m1589467547_gshared (blob:254355:7)
_U3CInstantiateFromABU3Ec__Iterator2_MoveNext_m2663907703 (blob:155266:4)
mftCall_iii (blob:518890:64)
__ZN21InterfaceFuncInvoker0IbE6InvokeEjP11Il2CppClassP12Il2CppObject (blob:268908:9)
_SetupCoroutine_InvokeMoveNext_m3687002044 (blob:366448:21)
mftCall_viiii (blob:496403:3)
__Z53RuntimeInvoker_Void_t105822878_RuntimeObject_IntPtr_tPFvvEPK10MethodInfoPvPS4_ (blob:506753:2)
mftCall_iiiii (blob:495126:64)
__ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException (blob:482326:9)
_il2cpp_runtime_invoke (blob:491439:9)
_il2cpp_runtime_invoke [asm._il2cpp_runtime_invoke] (blob:671712:10)
_il2cpp_runtime_invoke (VisionneuseWebGL.asm.framework.unityweb:11642:9)
__Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb (blob:2696456:1)
__ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb (blob:2083494:1)
__ZN9Coroutine14InvokeMoveNextEP21ScriptingExceptionPtr (blob:2308276:1)
__ZN9Coroutine3RunEPb (blob:2393165:1)
__ZN9Coroutine17ContinueCoroutineEP6ObjectPv (blob:2797523:1)
mftCall_iii (blob:2849661:1)
__ZN14AsyncOperation15InvokeCoroutineEv (blob:1827720:1)
__ZN14PreloadManager26UpdatePreloadingSingleStepENS_21UpdatePreloadingFlagsEi (blob:1298697:1)
__ZN14PreloadManager16UpdatePreloadingEv (blob:1714158:1)
__ZZ23InitPlayerLoopCallbacksvEN38EarlyUpdateUpdatePreloadingRegistrator7ForwardEv (blob:2459690:1)
mftCall_v (blob:2888261:1)
__Z10PlayerLoopv (blob:810392:1)
__ZL8MainLoopv (blob:2135425:1)
ce6e49761d2c31df7859c6e83cd6c075 [UnityLoader.ce6e49761d2c31df7859c6e83cd6c075/asm.__ZL8MainLoopv] (VisionneuseWebGL.asm.framework.unityweb:208994:9)
ftCall_v (VisionneuseWebGL.asm.framework.unityweb:30706:9)
browserIterationFunc (VisionneuseWebGL.asm.framework.unityweb:11460:4)
runIter (VisionneuseWebGL.asm.framework.unityweb:10858:5)
Browser_mainLoop_runner (VisionneuseWebGL.asm.framework.unityweb:11498:3)

Error on my profiler (I couldn’t copy/paste it easily):

Could not produce class with ID 111 and 74. This could be caused by a class being stripped by the build even though it is needed. Try disabling 'Strip Engine Code' in player settings.

So I wrote a link.xml file to exclude some classe being stripped and I put it into my assets repository. But it didn’t change anything…

<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.Animation" preserve="all"/>
<type fullname="UnityEngine.AnimationClip" preserve="all"/>
</assembly>
</linker>

So, does anyone know why link.xml seems to have no effect ? Is there another proper way to exclude some class of stripping process ?

Thank you for reading this, hope someone will be able to help :wink:

The link.xml file only impacts stripping of managed code, In this case, it looks like native engine code that is used only in your asset bundle (and not in any scene in the build) is being removed. That is why link.xml won’t help.

You have three options.

  1. Like the error message says, you can disable engine code stripping in the Player Settings. This will increase the size of the build, but you won’t have to worry about what you use in asset bundles.
  2. You can create a dummy scene in the build which uses the engine code types that are used in your asset bundles. That way they won’t be removed by engine code stripping. Based on the error message, it seems you need to keep AnimationClip (class ID 74) and Animation (class ID 111).
  3. You can use a custom build configuration to tell the build process what engine code types the asset bundles you will load use. The build process will keep them around for you. See the asset bundle demo project for an example, specifically this code: https://bitbucket.org/Unity-Technologies/assetbundledemo/src/464697bcff9b5422e13950b9a9664cd0b3496d10/demo/Assets/AssetBundleManager/Editor/BuildScript.cs?at=default&fileviewer=file-view-default#BuildScript.cs-122