Cannot build Android IL2CPP for Unity

Hi. Everything used to run fine until about 4-5 months ago. This week I’ve been stuck at that issue. I cannot even build blank apps.

Here are the steps I’ve made:

  1. Create blank Unity project.

  2. Switch to Android.

  3. Under Player Settings, switch “Scripting Backend” from Mono to IL2CPP.

  4. Change Api Compatibility Level from .NET Standard 2.0 to .NET 4.x.

  5. Check Arm64 architecture (and make sure ARM7 is still checked).

  6. Change Package name to “com.testcompany.testapp”

  7. In Build Settings check the "Build App Bundle (Google Play) checkbox to ensure we get a .aab instead of a .apk.

So nothing special about the project. But when I build it, I get the error message below… Can anyone help, please?

Thank you.


Failed running C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="unityaot" --compile-cpp --libil2cpp-static --platform="Android" --architecture="ARMv7" --configuration="Release" --outputpath="C:\Programming\x Test Apps\TestBlank1\TestBlank1\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a\libil2cpp.so" --cachedirectory="C:\Programming\x Test Apps\TestBlank1\TestBlank1\Assets\..\Library\il2cpp_android_armeabi-v7a/il2cpp_cache" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.2.15f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.2.15f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include" --tool-chain-path="C:/Program Files/Unity/Hub/Editor/2019.2.15f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK/android-ndk-r16b" --profiler-report --map-file-parser="C:/Program Files/Unity/Hub/Editor/2019.2.15f1/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory="C:/Programming/x Test Apps/TestBlank1/TestBlank1/Temp/StagingArea/assets/bin/Data/Managed" --generatedcppdir="C:/Programming/x Test Apps/TestBlank1/TestBlank1/Temp/StagingArea/Il2Cpp/il2cppOutput" 

stdout:
Building libil2cpp.so with AndroidToolChain
	Output directory: C:\Programming\x Test Apps\TestBlank1\TestBlank1\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a
	Cache directory: C:\Programming\x Test Apps\TestBlank1\TestBlank1\Library\il2cpp_android_armeabi-v7a\il2cpp_cache
ObjectFiles: 110 of which compiled: 0
Total compilation time: 98 milliseconds.
il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"C:\Users\User\AppData\Local\Temp	mpB735.tmp" -o "C:\Programming\x Test Apps\TestBlank1\TestBlank1\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_E58CBCC113E4DAB418312994751884A4\libil2cpp.so" -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id --sysroot "C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b\platforms\android-16\arch-arm" -gcc-toolchain "C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -Wl,--wrap,sigaction -L "C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a" -lgnustl_static -latomic -llog -rdynamic -fuse-ld=gold.exe

C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.gold.exe: error: cannot open C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a/libatomic.a: No such file or directory
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)


   at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext)
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at il2cpp.Program.DoRun(String[] args)
   at il2cpp.Program.Run(String[] args)
   at il2cpp.Program.Main(String[] args)
stderr:

Unhandled Exception: Unity.IL2CPP.Building.BuilderFailedException: C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"C:\Users\User\AppData\Local\Temp	mpB735.tmp" -o "C:\Programming\x Test Apps\TestBlank1\TestBlank1\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_E58CBCC113E4DAB418312994751884A4\libil2cpp.so" -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id --sysroot "C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b\platforms\android-16\arch-arm" -gcc-toolchain "C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -Wl,--wrap,sigaction -L "C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a" -lgnustl_static -latomic -llog -rdynamic -fuse-ld=gold.exe

C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.gold.exe: error: cannot open C:\Program Files\Unity\Hub\Editor\2019.2.15f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\android-ndk-r16b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a/libatomic.a: No such file or directory
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)


   at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet`1 objectFiles, CppToolChainContext toolChainContext)
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at il2cpp.Program.DoRun(String[] args)
   at il2cpp.Program.Run(String[] args)
   at il2cpp.Program.Main(String[] args)

UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:126)
UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:71)
UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:503)
UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(String, String, String, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:484)
UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:334)
UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:63)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)

Finally figured it out. I read somewhere that only the NDK r16b works. Surely enough, I was referencing the most up-to-date NDK (r20b at the moment).

So I downloaded the r16b library and changed the Path in the Unity Preferences. Now it’s functioning correctly.

And here’s the download link: Unsupported Downloads · android/ndk Wiki · GitHub

remove old sdk and add nu sdk with full update

On my computer, that was a too long path error.

Install NDK 16R somewhere close to the root of your HD and set the path in the NDK path setup.,The issue, on my computer, was a path too long. So i just install the NDK outside Unity folders and every thing works.

If you still encounter this issue, I suggest to install the latest version of Unity 2019, it fixes all of the issues related to NDK. I just did so.

I moved my NDK to my desktop and then had to manually browse for it in Unity. I’m not sure if manually selecting it was what fixed the issue or if it needed to be in a different folder, but whatever it was it seems to be working fine now