Search code examples
androidunity-game-enginesocket.ioapk

How to prevent code stripping with IL2CPP?


We are making our first small Unity Android game. App connects to our Socket.IO server and sends/receives some data. Everything works fine during development. We connect device via USB, use Unity Remote 5 on device, app connects to server and everything is great.

Then we build signed APK from Unity. We install APK to same device, app starts without problem, but socket.io communication doesn't work. At server side, I can see initial request to connect (which is successful), but then app won't connect to specified namespace, and it doesn't send requests to load data.

Are we making some obvious mistake? Do we have to specify something else to build working APK? We are only adding keystore to sign release. It seems that network communication is enabled in release APK, because we see some requests. We are Unity beginners, any help is appreciated.

We use Unity 2019.1.11f1. We use this socket.io client library: https://github.com/doghappy/socket.io-client-csharp

We have tried other library: https://github.com/Quobject/SocketIoClientDotNet but encountered same problem. Works during development, doesn't work in release APK. We have also tried 2 different Socket.IO server implementation, both (Flask and go-socket.io) behaved same.

EDIT: We have done more testing and found out, that when using Mono, everything works fine. But when we switch to IL2CPP, APK is broken. We have to use IL2CPP because of Play store (required 64-bit). Our current theory is too aggressive code stripping that removes some important part of code.

So, question should be, how to prevent code stripping with IL2CPP?


Solution

  • Not sure if it's actually in any way related to your issues, but code stripping has a proper setting in the engine:

    https://docs.unity3d.com/Manual/ManagedCodeStripping.html