Addressables and Code Stripping (IL2CPP)

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.

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]]
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

System.RuntimeType.CreateInstanceMono (System.RuntimeType)
System.Activator.CreateInstance (System.Activator)
UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy.New (UnityEngine.ResourceManagement.Util.LRUCacheAllocationStrategy)
UnityEngine.ResourceManagement.ResourceManager.CreateOperation[T] (UnityEngine.ResourceManagement.ResourceManager)
UnityEngine.ResourceManagement.ResourceManager.ProvideResource (UnityEngine.ResourceManagement.ResourceManager)
UnityEngine.ResourceManagement.ResourceManager.ProvideResource[TObject] (UnityEngine.ResourceManagement.ResourceManager)
UnityEngine.AddressableAssets.Initialization.InitializationOperation.CreateInitializationOperation (UnityEngine.AddressableAssets.Initialization.InitializationOperation)
UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync (UnityEngine.AddressableAssets.AddressablesImpl)
UnityEngine.AddressableAssets.AddressablesImpl.get_InitializationOperation (UnityEngine.AddressableAssets.AddressablesImpl)
UnityEngine.AddressableAssets.AddressablesImpl.DownloadDependenciesAsync (UnityEngine.AddressableAssets.AddressablesImpl)

Has anyone had this issue and has it been solved?

2 Likes

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.

4 Likes

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.

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.

1 Like

Yeah you are correct. It’s the result of code stripping + forgetting to build player content for the platform.

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

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]]
  at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <71d402037f2643fe94cabbbe0d22d04d>:0
  at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <71d402037f2643fe94cabbbe0d22d04d>:0
  at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <71d402037f2643fe94cabbbe0d22d04d>:0
  at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <71d402037f2643fe94cabbbe0d22d04d>:0
  at System.Activator.CreateInstance (System.Type type) [0x00000] in <71d402037f2643fe94cabbbe0d22d04d>:0
  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
  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
  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
  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
  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
  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
  at UnityEngine.AddressableAssets.AddressablesImpl.InitializeAsync () [0x00013] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\AddressablesImpl.cs:289
  at UnityEngine.AddressableAssets.AddressablesImpl.get_InitializationOperation () [0x00013] in D:\Project\Designer\Designer\Library\PackageCache\com.unity.addressables@1.1.9\Runtime\AddressablesImpl.cs:306
  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
  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
  at Ubiant.Common.Adressables.AddressablesLoader+<InitializeAddressables>d__2.MoveNext () [0x00020] in D:\Project\Designer\Designer\Assets\Scripts\Runtime\Addressables\AddressablesLoader.cs:49
  at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00027] in <1cc3984764e64bdeb5a66b5d2a3bc7e1>:0
UnityEngine.MonoBehaviour:StartCoroutineManaged2(IEnumerator)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
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 :confused:

If you have any solution that could allow us to maintain the stripping and avoid this issue it could be cool :slight_smile:

1 Like

@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).

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.

Except if I set the wrong lib inside, it didn’t work for me.

Happens to me today, it worked before, and I didn’t update my plugin. what’s the cause?

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.

1 Like

it helped me

add link.xml file to the Assets folder

<linker>
    <assembly fullname="Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
    <type fullname="UnityEngine.ResourceManagement.ResourceProviders.LegacyResourcesProvider" preserve="all" />
    <type fullname="UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider" preserve="all" />
    <type fullname="UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider" preserve="all" />
    <type fullname="UnityEngine.ResourceManagement.ResourceProviders.InstanceProvider" preserve="all" />
    <type fullname="UnityEngine.ResourceManagement.AsyncOperations" preserve="all" />
    </assembly>
    <assembly fullname="Unity.Addressables, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" preserve="all">
    <type fullname="UnityEngine.AddressableAssets.Addressables" preserve="all" />
    </assembly>
</linker>
19 Likes

I had this problem and realized it’s because you now need to separately build in the Addresseables menu before your main build. See How to trigger "build player content" when build unity project. and Getting started with Addressable Assets | Package Manager UI website

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.

15 Likes

Had met the same error in the iOS & standalone build today.
I do the steps what you said. Yes! it works!
Thank you! You save my time… :smile:

Thank you, I just built Addressables before the main build and it is working well.

3 Likes

Hello!
Could you describe a bit more the process? Where did you put AddressableAssetSettings.CleanPlayerContent and AddressableAssetSettings.BuildPlayerContent ?
I have this error since yesterday!

Thank you! This was the problem, not IL2CPP stripping the assemblies

To address the original question in this thread…

Cleanest solution is to add this include somewhere:

using UnityEngine.ResourceManagement.AsyncOperations;
2 Likes

I just add the same problem after switching platform to Android and trying to build right away.
I got rid of the error by updating the addressables build and then trying to build the APK again.

This saved me.