Search code examples
c#unity-game-engineil2cppamazon-gamelift

Google.Protobuf.Reflection is not working with il2cpp scripting in Unity


I was creating an android game in unity3d using amazon gamelift.
I am using realtime server client sdk. When I run the app it creating a game session in my gamelift fleet but is not able to send messages when I am using IL2CPP sever scripting.
It was working fine when I was using Mono but after switching to IL2CPP I am facing many repairs, I found solutions for many errors but not able to find solution for this particular error. It seems that Google.Protbuff.Reflection is not working with IL2CPP.Error is showning it cannot find method ClearMessage even though it is there.
Can anyone please help me..

   Exception occurred sending data. Exception: The type initializer for 'Com.Gamelift.Rt.Proto.PacketReflection' threw an exception.
<br>
System.ArgumentException: Invalid embedded descriptor for "proto/Packet.proto". 
<br>
<b>Stacktrace:</b><br>
Google.Protobuf.Reflection.DescriptorValidationException: com.gamelift.rt.proto.Packet.message: Method ClearMessage not found in Com.Gamelift.Rt.Proto.Packet<br>
      at Google.Protobuf.Reflection.OneofDescriptor.CreateAccessor (System.String clrName) [0x00000] in <00000000000000000000000000000000>:0 <br>
      at Google.Protobuf.Reflection.OneofDescriptor..ctor (Google.Protobuf.Reflection.OneofDescriptorProto proto, Google.Protobuf.Reflection.FileDescriptor file, Google.Protobuf.Reflection.MessageDescriptor parent, System.Int32 index, System.String clrName) [0x00000] in <00000000000000000000000000000000>:0 <br>
      at Google.Protobuf.Reflection.MessageDescriptor+<>c__DisplayClass4_0.<.ctor>b__0 (Google.Protobuf.Reflection.OneofDescriptorProto oneof, System.Int32 index) [0x00000] in <00000000000000000000000000

Solution

  • That code accessed only through reflection was stripped because IL2CPP did not know it was needed, and that was solved by link.xml with the contents (DataModelBindings is a .NET lib of all my protoc generated code)

    <linker> <assembly fullname="DataModelBindings" preserve="all"/> </linker>