Search Unity

Addressables and Code Stripping (IL2CPP)

Discussion in 'Addressables' started by CharBodman, Jun 25, 2019.

  1. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    28
    Hi there,

    We've just recently enabled code stripping in our game and we've hit a problem with the Addressables package. ProviderOperation is being stripped due to the use of reflection.

    Code (CSharp):
    1. MissingMethodException : Default constructor not found for type UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1[[UnityEngine.AddressableAssets.Initialization.ResourceManagerRuntimeData, Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
    2. System.RuntimeType.CreateInstanceMono
    I don't believe we can use link.xml as a way to fix the problem due to the use of generics

    The culprit is
    Line 259 - Resource.cs 
    .

    Extended stack trace
    Code (CSharp):
    1. System.RuntimeType.CreateInstanceMono (System.RuntimeType)
    2. System.Activator.CreateInstance (System.Activator)
    3. UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy)
    4. UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (UnityEngine.ResourceManagement.ResourceManager)
    5. UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceManagement.ResourceManager)
    6. UnityEngine.ResourceManagement.ResourceManager.ProvideResource[TObject] (UnityEngine.ResourceManagement.ResourceManager)
    7. UnityEngine.AddressableAssets.Initialization.InitializationOperation.CreateInitializationOperation (UnityEngine.AddressableAssets.Initialization.InitializationOperation)
    8. UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (UnityEngine.AddressableAssets.AddressablesImpl)
    9. UnityEngine.AddressableAssets.AddressablesImpl.get_InitializationOperation (UnityEngine.AddressableAssets.AddressablesImpl)
    10. UnityEngine.AddressableAssets.AddressablesImpl.DownloadDependenciesAsync (UnityEngine.AddressableAssets.AddressablesImpl)
    Has anyone had this issue and has it been solved?
     
  2. KHUnity7

    KHUnity7

    Joined:
    Feb 27, 2018
    Posts:
    3
    Been having the exact error message on ios at run time yesterday. But found out we were missing the Addressable Packages for the build, so put the AddressableAssetSettings.CleanPlayerContent and then AddressableAssetSettings.BuildPlayerContent in the build process before buildplayer, and it works on device. [for the assets setup within static assets packs]

    Didn't even try the stripping code settings.

    Not sure that will be working for you.
     
    Last edited: Jun 26, 2019
    shvanjan likes this.
  3. Fesener

    Fesener

    Joined:
    May 3, 2018
    Posts:
    33
    I had the same exact problem with v1.1.4 and v1.1.3, switching back to v0.8.6 fixed the issue for me.
     
    Last edited: Jun 27, 2019
  4. dforstmaier

    dforstmaier

    Joined:
    Oct 5, 2016
    Posts:
    3
    Thanks Fesener, that downgrade to v0.8.6 solved the problem for me, too.

    Also it had no effect whether Code Stripping was activated or not.
     
    Fesener likes this.
  5. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    28
    Yeah you are correct. It's the result of code stripping + forgetting to build player content for the platform.
     
  6. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    259
    @unity_bill

    We currently have the same issue in our project here.
    I really think it's a bug due to the 0.8.6 rollback that fix the issue.

    Code (CSharp):
    1. MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.AsyncOperations.ProviderOperation`1[[UnityEngine.AddressableAssets.Initialization.ResourceManagerRuntimeData, Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]
    2.   at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <71d402037f2643fe94cabbbe0d22d04d>:0
    3.   at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <71d402037f2643fe94cabbbe0d22d04d>:0
    4.   at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <71d402037f2643fe94cabbbe0d22d04d>:0
    5.   at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <71d402037f2643fe94cabbbe0d22d04d>:0
    6.   at System.Activator.CreateInstance (System.Type type) [0x00000] in <71d402037f2643fe94cabbbe0d22d04d>:0
    7.   at UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (System.Type type, System.Int32 typeHash) [0x00055] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\ResourceManager\Util\ResourceManagerConfig.cs:134
    8.   at UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (System.Type actualType, System.Int32 typeHash, System.Int32 operationHash, System.Action`1[T] onDestroyAction) [0x00032] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\ResourceManager\ResourceManager.cs:358
    9.   at UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location, System.Type desiredType) [0x000d1] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\ResourceManager\ResourceManager.cs:260
    10.   at UnityEngine.ResourceManagement.ResourceManager.ProvideResource[TObject] (UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation location) [0x00001] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\ResourceManager\ResourceManager.cs:287
    11.   at UnityEngine.AddressableAssets.Initialization.InitializationOperation.CreateInitializationOperation (UnityEngine.AddressableAssets.AddressablesImpl aa, System.String playerSettingsLocation, System.String providerSuffix) [0x0009a] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\Initialization\InitializationOperation.cs:42
    12.   at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (System.String runtimeDataPath, System.String providerSuffix) [0x0008d] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\AddressablesImpl.cs:280
    13.   at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync () [0x00013] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\AddressablesImpl.cs:289
    14.   at UnityEngine.AddressableAssets.AddressablesImpl.get_InitializationOperation () [0x00013] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\AddressablesImpl.cs:306
    15.   at UnityEngine.AddressableAssets.AddressablesImpl.LoadContentCatalogAsync (System.String catalogPath, System.String providerSuffix) [0x0004c] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\AddressablesImpl.cs:296
    16.   at UnityEngine.AddressableAssets.Addressables.LoadContentCatalogAsync (System.String catalogPath, System.String providerSuffix) [0x00001] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\Addressables.cs:231
    17.   at Ubiant.Common.Adressables.AddressablesLoader+<InitializeAddressables>d__2.MoveNext () [0x00020] in D:\Project\Designer\Designer\Assets\Scripts\Runtime\Addressables\AddressablesLoader.cs:49
    18.   at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00027] in <1cc3984764e64bdeb5a66b5d2a3bc7e1>:0
    19. UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
    20. UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    21. Ubiant.Designer.Managers.ApplicationManager:Awake() (at D:\Project\Designer\Designer\Assets\Scripts\Runtime\Misc\ApplicationManager.cs:48)

    We currently use the addressables package in a project where no addressables are built. So for me it's pointless to call the Clean / Build process step in PreBuild phase just to hook the compiler and tell him "Hello, addressables are here please don't strip them in my runtime build".

    By the way, it's not linked to IL2CPP but just to the fact that we activated the stripping process into PlayerSettings.

    Any idea on this particular problem ?

    I bring another precision on the solution found in the above post.
    - For us here the Clean/Build player content solution doesn't work at all.
    - link.xml couldn't be used due to the non IL2CPP target (standalone build) it's not used on mono backend.
    - Disabled stripping works but it's not a really good workaround :/

    If you have any solution that could allow us to maintain the stripping and avoid this issue it could be cool :)
     
    Last edited: Aug 26, 2019
    LUCID-Rob likes this.
  7. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    259
    @unity_bill If you need it, I could send you a repro project tomorrow morning here.
    Even if it's quite simple to repro.
    - Include Addressables asset package (version above 0.8.6)
    - Activate stripping level to low or above in player settings.
    - Make some call to the addressable in the project to load a distant catalog built from another project and put on a server.
    - Build the current project without generating any AddressablesAssetSettings.
    - You must see pop our issue at runtime due to the stripping removing Addressables and ResourceManagement from build (stripped them).
     
  8. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    706
    Is it not? As far as I am aware it's part of UnityLinker, which I thought was used for both Mono and IL2CPP builds.

    Edit: Reading the docs, it quite explicitly states that it is used for all builds, the differences in its behaviour between IL2CPP and Mono are outlined in some detail.
     
  9. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    259
    Except if I set the wrong lib inside, it didn't work for me.
     
  10. cdytoby

    cdytoby

    Joined:
    Nov 19, 2014
    Posts:
    157
    Happens to me today, it worked before, and I didn't update my plugin. what's the cause?
     
  11. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    45
    Could you go into more details on how to add these to the build process? This issue is really frustrating for me and makes me wish I hadn't tried using Addressables. I don't even have the option to roll back that far.
     
    travlake likes this.
  12. MontanaAnton

    MontanaAnton

    Joined:
    Feb 16, 2014
    Posts:
    5
    it helped me

    add link.xml file to the Assets folder

    Code (JavaScript):
    1.  
    2. <linker>
    3.     <assembly fullname="Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
    4.     <type fullname="UnityEngine.ResourceManagement.ResourceProviders.LegacyResourcesProvider" preserve="all" />
    5.     <type fullname="UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider" preserve="all" />
    6.     <type fullname="UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider" preserve="all" />
    7.     <type fullname="UnityEngine.ResourceManagement.ResourceProviders.InstanceProvider" preserve="all" />
    8.     <type fullname="UnityEngine.ResourceManagement.AsyncOperations" preserve="all" />
    9.     </assembly>
    10.     <assembly fullname="Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
    11.     <type fullname="UnityEngine.AddressableAssets.Addressables" preserve="all" />
    12.     </assembly>
    13. </linker>
    14.  
     
  13. travlake

    travlake

    Joined:
    Oct 4, 2019
    Posts:
    2
    I had this problem and realized it's because you now need to separately build in the Addresseables menu before your main build. See https://forum.unity.com/threads/how-to-trigger-build-player-content-when-build-unity-project.689602/ and https://docs.unity3d.com/Packages/c...3/manual/AddressableAssetsGettingStarted.html

    I built in Addressables Menus (Window -> Asset Management -> Addressables -> Groups. Then Build -> New Build -> Default Build Script from the top bar), and it worked in Run-Time.
     
unityunity