CaspianArts
CaspianArts

Reputation: 23

Is there a way to prevent assembly stripping in Unity for the IL2CPP compiler in order to use the AWS Gamelift API?

Apparently the AWS Gamelift API uses reflection or some mechanism that causes the Unity compilers to over aggressively strip required assemblies. As a result, you are limited to using the Mono compiler which does allow for turning off stripping. IL2CPP does not have a similar option. For IL2CPP, you can control the stripping through entries in the link.xml file (\Assets\link.xml). So far, I have not had success using the link.xml approach.

After using the entries below in the link.xml, a number of exceptions are prevented, but this exception still remains.

2020-03-16 12:12:14.622 13883-13898/com.company.app E/Unity: NotSupportedException: System.Configuration.ConfigurationManager::get_AppSettings at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <00000000000000000000000000000000>:0 at Amazon.AWSConfigs.GetConfig (System.String name) [0x00000] in <00000000000000000000000000000000>:0 at Amazon.AWSConfigs..cctor () [0x00000] in <00000000000000000000000000000000>:0 at Amazon.Runtime.ClientConfig..ctor () [0x00000] in <00000000000000000000000000000000>:0 at Amazon.GameLift.AmazonGameLiftConfig..ctor () [0x00000] in <00000000000000000000000000000000>:0 at Amazon.GameLift.AmazonGameLiftClient..ctor (System.String awsAccessKeyId, System.String awsSecretAccessKey, Amazon.RegionEndpoint region) [0x00000] in <00000000000000000000000000000000>:0 at GameLiftClient.GetConnectionInfo (System.String& ip, System.Int32& port, System.String& playerSessionId) [0x00000] in <00000000000000000000000000000000>:0 at GameLift.GetConnectionInfo (System.String& ip, System.Int32& port, System.String

link.xml

<linker>
  <assembly fullname="UnityEngine">
    <type fullname="UnityEngine.Networking.UnityWebRequest" preserve="all" />
    <type fullname="UnityEngine.Networking.UploadHandlerRaw" preserve="all" />
    <type fullname="UnityEngine.Networking.UploadHandler" preserve="all" />
    <type fullname="UnityEngine.Networking.DownloadHandler" preserve="all" />
    <type fullname="UnityEngine.Networking.DownloadHandlerBuffer" preserve="all" />
  </assembly>
  <assembly fullname="mscorlib">
      <namespace fullname="System.Security.Cryptography" preserve="all"/>
  </assembly>
  <assembly fullname="System">
      <namespace fullname="System.Security.Cryptography" preserve="all"/>
  </assembly>
  <assembly fullname="AWSSDK.Core" preserve="all"/>
  <assembly fullname="AWSSDK.CognitoIdentity" preserve="all"/>
  <assembly fullname="AWSSDK.CognitoSync" preserve="all"/>
  <assembly fullname="AWSSDK.DynamoDBv2" preserve="all"/>
  <assembly fullname="AWSSDK.Kinesis" preserve="all"/>
  <assembly fullname="AWSSDK.KinesisFirehose" preserve="all"/>
  <assembly fullname="AWSSDK.Lambda" preserve="all"/>
  <assembly fullname="AWSSDK.MobileAnalytics" preserve="all"/>
  <assembly fullname="AWSSDK.S3" preserve="all"/>
  <assembly fullname="AWSSDK.SecurityToken" preserve="all"/>
  <assembly fullname="AWSSDK.SimpleEmail" preserve="all"/>
  <assembly fullname="AWSSDK.SimpleNotificationService" preserve="all"/>
  <assembly fullname="AWSSDK.SQS" preserve="all"/>
  <assembly fullname="AWSSDK.IdentityManagement" preserve="all"/>
  <assembly fullname="AWSSDK.GameLift" preserve="all"/>
  <assembly fullname="System.Configuration" preserve="all"/>
  <assembly fullname="System.SecurityUtils" preserve="all"/>
  <assembly fullname="System.ComponentModel" preserve="all"/>
  <assembly fullname="System.Activator" preserve="all"/>
  <assembly fullname="System.RuntimeType" preserve="all"/>
</linker>

Is there anyway, using the link.xml or another mechanism, to disable assembly stripping in Unity so that the IL2CPP compiler may be used?

Upvotes: 1

Views: 1717

Answers (2)

CaspianArts
CaspianArts

Reputation: 23

Following Josh Peterson's answer, the solution is to use the link.xml file to prevent stripping AND to use modified versions of the AWSSDK.Core and AWSSDK.GameLift libraries that do not include the System Configuration Manager.

The following forked version of the AWSSDK GitHub project's entire purpose is to solve the problem of compiling against IL2CPP and using GameLift.

https://github.com/fixstu/aws-sdk-net

By first building the AWSSDK.Core.Net45.csproj, then building the AWSSDK.GameLift.Net35.csproj, both necessary libraries will be output to the /sdk/src/Services/GameLift/ directory.

Add the output binaries to the Unity project's /Assets/Plugin directory and the link.xml to the /Assets directory...and IL2CPP will compile and run GameLift commands without exceptions.

Upvotes: 1

Josh Peterson
Josh Peterson

Reputation: 2329

This error is not related to managed code stripping, actually. This happens because IL2CPP does not support System.Configuration.ConfigurationManager.

You'll need to see if it is possible to use the AWS Gamelift API without accessing the configuration manager API.

Upvotes: 1

Related Questions