aws-samples / amazon-gamelift-unity

A multi-player game sample (server and client), developed with the Unity game engine, illustrating basic integration with Amazon GameLift. View the sample source code or build the project and experiment with game server deployment on the Amazon GameLift service.
Apache License 2.0
82 stars 22 forks source link

IL2CPP Android Error #15

Open Dankann opened 3 years ago

Dankann commented 3 years ago

I followed the steps to test this sample project and everything works fine on desktop builds. The problems starts after testing the sample on android player.

At first I was having a similar problem to this issue, my log was:

NotSupportedException: System.Configuration.ConfigurationManager::get_AppSettings
02-18 11:54:25.026 27935  7064 E Unity   :   at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Amazon.AWSConfigs.GetConfig (System.String name) [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Amazon.AWSConfigs..cctor () [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Amazon.Runtime.Internal.Util.TraceSourceUtil.GetTraceSourceWithListeners (System.String name, System.Diagnostics.SourceLevels sourceLevels) [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Amazon.Runtime.Internal.Util.Logger..ctor (System.Type type) [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Amazon.Runtime.Internal.Util.Logger.GetLogger (System.Type type) [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Amazon.Runtime.CredentialManagement.SharedCredentialsFile..ctor () [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.026 27935  7064 E Unity   :   at Credentials.MigrateProfile () [0x00000] in <00000000000000000000000000000
02-18 11:54:25.028 27935  7072 E Unity   : NullReferenceException: Object reference not set to an instance of an object.
02-18 11:54:25.028 27935  7072 E Unity   :   at GameLiftClient.Finalize () [0x00000] in <00000000000000000000000000000000>:0
02-18 11:54:25.028 27935  7072 E Unity   : System.UnhandledExceptionEventHandler:Invoke(Object, UnhandledExceptionEventArgs)
02-18 11:54:25.028 27935  7072 E Unity   :
02-18 11:54:25.028 27935  7072 E Unity   : (Filename: currently not available on il2cpp Line: -1)

So I replaced the current AWS SDK Core for the NetStandard 2.0 one.

I also added a link.xml file to the project:

<linker>
    <!--  if you are using AWSConfigs.HttpClient.UnityWebRequest option -->
    <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"/>
        <type fullname="System.ComponentModel.TypeConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ArrayConverter" preserve="all"/>
        <type fullname="System.ComponentModel.BaseNumberConverter" preserve="all"/>
        <type fullname="System.ComponentModel.BooleanConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ByteConverter" preserve="all"/>
        <type fullname="System.ComponentModel.CharConverter" preserve="all"/>
        <type fullname="System.ComponentModel.CollectionConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ComponentConverter" preserve="all"/>
        <type fullname="System.ComponentModel.CultureInfoConverter" preserve="all"/>
        <type fullname="System.ComponentModel.DateTimeConverter" preserve="all"/>
        <type fullname="System.ComponentModel.DecimalConverter" preserve="all"/>
        <type fullname="System.ComponentModel.DoubleConverter" preserve="all"/>
        <type fullname="System.ComponentModel.EnumConverter" preserve="all"/>
        <type fullname="System.ComponentModel.ExpandableObjectConverter" preserve="all"/>
        <type fullname="System.ComponentModel.Int16Converter" preserve="all"/>
        <type fullname="System.ComponentModel.Int32Converter" preserve="all"/>
        <type fullname="System.ComponentModel.Int64Converter" preserve="all"/>
        <type fullname="System.ComponentModel.NullableConverter" preserve="all"/>
        <type fullname="System.ComponentModel.SByteConverter" preserve="all"/>
        <type fullname="System.ComponentModel.SingleConverter" preserve="all"/>
        <type fullname="System.ComponentModel.StringConverter" preserve="all"/>
        <type fullname="System.ComponentModel.TimeSpanConverter" preserve="all"/>
        <type fullname="System.ComponentModel.UInt16Converter" preserve="all"/>
        <type fullname="System.ComponentModel.UInt32Converter" preserve="all"/>
        <type fullname="System.ComponentModel.UInt64Converter" preserve="all"/>
    </assembly>
    <assembly fullname="Google.Protobuf" preserve="all"/>
    <assembly fullname="GameLiftRealtimeClientSdkNet45" preserve="all" />
    <assembly fullname="SuperSocket.ClientEngine" preserve="all" />
    <assembly fullname="WebSocket4Net" preserve="all" />

    <assembly fullname="AWSSDK.Core" preserve="all">
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>
    <assembly fullname="AWSSDK.CognitoIdentity" preserve="all">
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>
    <assembly fullname="AWSSDK.SecurityToken" preserve="all">
        <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>

    <assembly fullname="System.Reflection" preserve="all"/>
    <assembly fullname="System.Collections.Immutable" preserve="all"/>
    <assembly fullname="System.Memory" preserve="all"/>
    <assembly fullname="System.Buffers" preserve="all"/>
    <assembly fullname="System.Runtime.CompilerServices.Unsafe" preserve="all"/>
    <assembly fullname="log4net" preserve="all"/>
    <assembly fullname="GameLiftServerSDKNet45" preserve="all"/>
    <assembly fullname="Newtonsoft.Json" preserve="all"/>
    <assembly fullname="websocket-sharp" preserve="all"/>

    <assembly fullname="AWSSDK.DynamoDBv2" preserve="all"/>
    <assembly fullname="AWSSDK.Lambda" preserve="all"/>
</linker>

The other modifications were to hard code credentials and alias so that the android player automatically tries to connect to the GameLift server. I tested it on unity editor both on windows and android build targets, on a windows build using IL2CPP and everything works fine, the android player with IL2CPP is the only one that has problems.

If you are testing this make sure to change attributes aliasId, profileNameon GameLiftClient class, also change accessKey and privateKey params on the new Amazon.Runtime.BasicAWSCredentials("my accessKey", "my secretKey"); call, line 380 on GameLift.cs file

This is the log from the android player, the problem seems to be on the NetworkClient.Connect() method: https://i.imgur.com/KP0FIm6.png

02-18 22:42:54.597 15820 26082 I Unity   : :) GAMELOGIC AWAKE
02-18 22:42:54.597 15820 26082 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
02-18 22:42:54.597 15820 26082 I Unity   : UnityEngine.Logger:Log(LogType, Object)
02-18 22:42:54.597 15820 26082 I Unity   : UnityEngine.Debug:Log(Object)
02-18 22:42:54.597 15820 26082 I Unity   : GameLogic:Awake()
02-18 22:42:54.597 15820 26082 I Unity   :
02-18 22:42:54.597 15820 26082 I Unity   : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
02-18 22:42:54.597 15820 26082 I Unity   :
02-18 22:42:54.599 15820 26082 I Unity   : :) GAMELIFT AWAKE
02-18 22:42:54.599 15820 26082 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
02-18 22:42:54.599 15820 26082 I Unity   : UnityEngine.Logger:Log(LogType, Object)
02-18 22:42:54.599 15820 26082 I Unity   : UnityEngine.Debug:Log(Object)
02-18 22:42:54.599 15820 26082 I Unity   : GameLift:Awake()
02-18 22:42:54.599 15820 26082 I Unity   :
02-18 22:42:54.599 15820 26082 I Unity   : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
02-18 22:42:54.599 15820 26082 I Unity   :
02-18 22:42:54.602 15820 26082 I Unity   : :) I AM CLIENT
02-18 22:42:54.602 15820 26082 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
02-18 22:42:54.602 15820 26082 I Unity   : UnityEngine.Logger:Log(LogType, Object)
02-18 22:42:54.602 15820 26082 I Unity   : UnityEngine.Debug:Log(Object)
02-18 22:42:54.602 15820 26082 I Unity   : GameLift:Awake()
02-18 22:42:54.602 15820 26082 I Unity   :
02-18 22:42:54.602 15820 26082 I Unity   : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
02-18 22:42:54.602 15820 26082 I Unity   :
02-18 22:42:54.667 15820 26082 D Unity   : Unable to lookup library path for 'Crypt32', native render plugin support disabled.
02-18 22:42:54.668 15820 26082 E Unity   : Unable to find Crypt32
02-18 22:42:54.682 15820 26082 E Unity   : AmazonClientException: The encrypted store is not available.  This may be due to use of a non-Windows operating system or Windows Nano Server, or the current user account may not have its profile loaded.
02-18 22:42:54.682 15820 26082 E Unity   :   at Amazon.Util.Internal.SettingsManager.EnsureAvailable () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at Amazon.Util.Internal.SettingsManager..ctor (System.String settingsType) [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at Amazon.Util.Internal.NamedSettingsManager..ctor (System.String settingsType) [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at Amazon.Runtime.CredentialManagement.NetSDKCredentialsFile..ctor () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at Credentials.MigrateProfile () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at Credentials.Install () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at GameLiftClient..ctor (GameLift _gl) [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.682 15820 26082 E Unity   :   at GameLift.Awake () [0x00000] in <00000000000000000000000000000
02-18 22:42:54.685 15820 26227 E Unity   : NullReferenceException: Object reference not set to an instance of an object.
02-18 22:42:54.685 15820 26227 E Unity   :   at GameLiftClient.DisposeGameLiftClient () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.685 15820 26227 E Unity   :   at GameLiftClient.Finalize () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.685 15820 26227 E Unity   : UnityEngine.DebugLogHandler:LogException(Exception, Object)
02-18 22:42:54.685 15820 26227 E Unity   : UnityEngine.Logger:LogException(Exception, Object)
02-18 22:42:54.685 15820 26227 E Unity   : UnityEngine.Debug:LogException(Exception)
02-18 22:42:54.685 15820 26227 E Unity   : UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)
02-18 22:42:54.685 15820 26227 E Unity   :
02-18 22:42:54.685 15820 26227 E Unity   : (Filename: currently not available on il2cpp Line: -1)
02-18 22:42:54.685 15820 26227 E Unity   :
02-18 22:42:54.718 15820 26082 D Unity   : Sensor :        Accelerometer ( 1) ; 0.002394 / 0.00s ; LSM6DSO Acceleration Sensor / STM
02-18 22:42:54.737 15820 26082 D Unity   : Choreographer available: Enabling VSYNC timing
02-18 22:42:54.742 15820 26082 I Unity   : :) GAMELOGIC START
02-18 22:42:54.742 15820 26082 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
02-18 22:42:54.742 15820 26082 I Unity   : UnityEngine.Logger:Log(LogType, Object)
02-18 22:42:54.742 15820 26082 I Unity   : UnityEngine.Debug:Log(Object)
02-18 22:42:54.742 15820 26082 I Unity   : GameLogic:Start()
02-18 22:42:54.742 15820 26082 I Unity   :
02-18 22:42:54.742 15820 26082 I Unity   : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
02-18 22:42:54.742 15820 26082 I Unity   :
02-18 22:42:54.753 15820 26082 I Unity   : CLIENT 0: Frame: 0 :) CONNECT TO LOCAL SERVER FAILED: PROBABLY NO LOCAL SERVER RUNNING, TRYING GAMELIFT
02-18 22:42:54.753 15820 26082 I Unity   : UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
02-18 22:42:54.753 15820 26082 I Unity   : UnityEngine.Logger:Log(LogType, Object)
02-18 22:42:54.753 15820 26082 I Unity   : UnityEngine.Debug:Log(Object)
02-18 22:42:54.753 15820 26082 I Unity   : Log:WriteLine(String)
02-18 22:42:54.753 15820 26082 I Unity   : NetworkClient:TryConnect(String, Int32, String)
02-18 22:42:54.753 15820 26082 I Unity   : NetworkClient:Connect()
02-18 22:42:54.753 15820 26082 I Unity   : NetworkClient:.ctor(GameLogic)
02-18 22:42:54.753 15820 26082 I Unity   : GameLogic:Start()
02-18 22:42:54.753 15820 26082 I Unity   :
02-18 22:42:54.753 15820 26082 I Unity   : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
02-18 22:42:54.753 15820 26082 I Unity   :
02-18 22:42:54.754 15820 26082 E Unity   : NullReferenceException: Object reference not set to an instance of an object.
02-18 22:42:54.754 15820 26082 E Unity   :   at GameLift.GetConnectionInfo (System.String& ip, System.Int32& port, System.String& auth) [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.754 15820 26082 E Unity   :   at NetworkClient.Connect () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.754 15820 26082 E Unity   :   at NetworkClient..ctor (GameLogic _gl) [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.754 15820 26082 E Unity   :   at GameLogic.Start () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.754 15820 26082 E Unity   :
02-18 22:42:54.754 15820 26082 E Unity   : (Filename: currently not available on il2cpp Line: -1)
02-18 22:42:54.754 15820 26082 E Unity   :
02-18 22:42:54.758 15820 26082 E Unity   : NullReferenceException: Object reference not set to an instance of an object.
02-18 22:42:54.758 15820 26082 E Unity   :   at GameLogic.get_Authoritative () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.758 15820 26082 E Unity   :   at GameLogic.Attract () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.758 15820 26082 E Unity   :   at GameLogic.Update () [0x00000] in <00000000000000000000000000000000>:0
02-18 22:42:54.758 15820 26082 E Unity   :
02-18 22:42:54.758 15820 26082 E Unity   : (Filename: currently not available on il2cpp Line: -1)

Repo with my changes: https://github.com/Dankann/amazon-unity-sample-android

Obs: Error Unable to find Crypt32 was already reported here

Dankann commented 3 years ago

@alanmur if you could take a look at this I would really appreciate it, thanks in advance.

alanmur commented 3 years ago

The clue may be in this:

AmazonClientException: The encrypted store is not available.  This may be due to use of a non-Windows operating system.

You may be able to point the client at a credentials file if you use this in the environment:

export AWS_CREDENTIAL_PROFILES_FILE=path/to/credentials_file

I don't have an Android development environment, so it may take a bit of effort for me to reproduce the problem.

Dankann commented 3 years ago

Hi @alanmur, thanks for the quick response I'm sorry but I don't quite get it, does this mean that I can't hard code the credentials? And if not, am I supposed to place the credentials file in the resources folder so that it is included in the build? Also, what exactly do you mean by setting this export AWS_CREDENTIAL_PROFILES_FILE in the environment?

Just an update, I tested another build with mono scripting backend and it gave me the same error so it may not be related to IL2CPP specifically.

alanmur commented 3 years ago

It's probable that upgrading to the latest AWS .NET SDK assemblies, and including a link.xml file in the project will resolve this issue.

From: https://docs.aws.amazon.com/sdk-for-net/latest/developer-guide/unity-special.html

"If you're using IL2CPP to build your Unity project, you must add a link.xml file to your Asset folder to prevent code stripping. The link.xml file must list all of the AWSSDK assemblies you are using, and each must include the preserve="all" attribute."