Debugging Android IL2CPP builds

Unity Team, did you plan update documentation with info about debugging Android IL2CPP builds?

Background: I have problem with strange freezes only in Android IL2CPP builds. It looks like Unity from time to time generate build which hang in this same place over and over, when making new build without changing anything in code or project settings generate perfectly fine build… But I’m not sure if it’s my fault or some strange bug in IL2CPP compiler.

Before freeze application doesn’t generate any error message, just stops react to any touch or even screen rotation event.

Is there any chance to attach debugger (ndk-gdb?) to Unity build and get native stack traces to figure out where freezes/errors occur? On iOS I can use Xcode integrated debugger but with Android I have no idea how to debug IL2CPP applications. Sadly I can’t reproduce this bug with IL2CPP iOS or Android Mono versions.

1 Like

How to debug Android IL2CPP builds:

  1. Export project with Gradle build system.
  2. Import project in Android Studio.
  3. Create run/debug configuration for android app with debug type (debugger tab) set to native.
  4. Run build.

To set breakpoints use symbolic breakpoints and function/method names from generated by IL2CPP code. Project specific generated C++ code are stored in $PROJECT/Temp/StagingArea/Il2Cpp/il2cppOutput, some shared code are available in $UNITY/Contents/il2cpp/. Function and method names you can always get from generated map file (libil2cpp.map).

Probably problems:

  1. Latest Unity 5.6.x create Gradle build script with outdated dependencies, if you get errors in build.gradle try update this line:
    dependencies {
    classpath ‘com.android.tools.build:gradle:2.2.0’
    }
    to
    dependencies {
    classpath ‘com.android.tools.build:gradle:2.3.3’
    }
1 Like

How can I debug Android IL2CPP builds with Visual Studio? I tried to attach the debugger to an Android device, but no USB device showed in the attach list. But if I build the app with Mono, there will be no problem attaching the debugger.

They should update documentation about this because they are becoming crazy all of us.

Managed code debugging should work with IL2CPP the same way it does with Mono. If not, please submit a bug report, as something is wrong. You can find the documentation here: https://docs.unity3d.com/Manual/ManagedCodeDebugging.html