ANDROID • BUILD & COMPILATION

ANDROID BUILD FAILED / COMMANDINVOKATIONFAILURE

CommandInvokationFailure: Gradle build failed or IL2CPP C++ compilation error while building APK / AAB for Android.

What Is the Error?

During the final packaging of an Android APK or Google Play App Bundle (.aab), Unity invokes the Android SDK, NDK, and Gradle toolchains. If paths are corrupted, JDK versions mismatch, target API levels are missing, or IL2CPP fails to compile C++ code for ARM64, Unity aborts with CommandInvokationFailure.

Primary Causes

  • Custom SDK / NDK Path Mismatches: Overriding the default Unity-installed NDK with an incompatible standalone Android Studio NDK version.
  • Outdated Target API Level: Google Play requires target API level 34+ (Android 14/15); building with an older SDK version causes export rejection.
  • IL2CPP C++ Compiler Failure: Missing ARM64 build symbols or plugins lacking 64-bit native libraries.
  • Invalid Keystore Passwords: Entering an incorrect alias password in the Publishing Settings.

Step-by-Step Fix

  1. Use Unity's Installed Tools (Recommended):

    Go to Edit > Preferences > External Tools. Ensure that JDK Installed with Unity, Android SDK Tools Installed with Unity, and Android NDK Installed with Unity are all CHECKED.

  2. Set Target API Level to Highest Installed:

    Go to Project Settings > Player > Android > Other Settings. Set Target API Level to Automatic (highest installed) or explicitly select API level 34 (Android 14).

  3. Configure IL2CPP & ARM64:

    Under Scripting Backend, select IL2CPP. Under Target Architectures, check both ARMv7 and ARM64 (Google Play rejects 32-bit only APKs).

  4. Delete Corrupted Gradle Cache:

    Delete the Library/Bee and Library/PlayerDataCache folders inside your project root, then restart Unity and rebuild.

Related Android Guides & Errors

Frequently Asked Questions

Mono builds directly compile intermediate C# bytecode (.dll). IL2CPP converts all your C# code and engine libraries into hundreds of thousands of native C++ source files, which are then fully compiled with Clang for ARM64 architectures. While slower to build, IL2CPP yields 2x to 3x higher CPU execution speed on mobile devices.