'Build - il2cpp did not run properly

I'm using unity 2019.2.0f1 with the integrating jdk-sdk and ndk recommended by unity to build a game for android platform first i build successfully my project using Mono after that i tried to build using IL2CPP unfortunately i couldn't build my game and got those errors in the console

    1error
Failed running C:\Program Files\Unity\Hub\Editor\2019.2.0f1\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:\Users\bechir\Documents\Unity 3D Projects\zagzig\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a\libil2cpp.so" --cachedirectory="C:\Users\bechir\Documents\Unity 3D Projects\zagzig\Assets\..\Library\il2cpp_android_armeabi-v7a/il2cpp_cache" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include" --additional-include-directories="C:/Program Files/Unity/Hub/Editor/2019.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include" --tool-chain-path="C:/Program Files/Unity/Hub/Editor/2019.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" --profiler-report --map-file-parser="C:/Program Files/Unity/Hub/Editor/2019.2.0f1/Editor/Data/Tools/MapFileParser/MapFileParser.exe" --directory="C:/Users/bechir/Documents/Unity 3D Projects/zagzig/Temp/StagingArea/assets/bin/Data/Managed" --generatedcppdir="C:/Users/bechir/Documents/Unity 3D Projects/zagzig/Temp/StagingArea/Il2Cpp/il2cppOutput" 

        stdout:
        Building libil2cpp.so with AndroidToolChain
            Output directory: C:\Users\bechir\Documents\Unity 3D Projects\zagzig\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a
            Cache directory: C:\Users\bechir\Documents\Unity 3D Projects\zagzig\Library\il2cpp_android_armeabi-v7a\il2cpp_cache
        il2cpp.exe didn't catch exception: System.AggregateException: Une ou plusieurs erreurs se sont produites. --->
        System.ComponentModel.Win32Exception: L'ex?cutable sp?cifi? n'est pas une application valide pour cette plateforme de syst?me d'exploitation.
           ?System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
           ?Unity.IL2CPP.Shell.Execute(ExecuteArgs executeArgs, IExecuteController controller)
           ?Unity.IL2CPP.Building.CppProgramBuilder.ProvideObjectFile(IntermediateObjectFileCompilationData data)
           ?Unity.IL2CPP.Building.ParallelFor.<>c__DisplayClass1_0`2.<RunWithResult>b__0(Object o)
           --- Fin de la trace de la pile d'exception interne ---
         Unity.IL2CPP.Building.ParallelFor.RunWithResult[D,T](D[] data, Func`2 action)
        Unity.IL2CPP.Building.CppProgramBuilder.BuildAllCppFiles(IEnumerable`1 sourceFilesToCompile, IBuildStatisticsCollector statisticsCollector)
        Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
        il2cpp.Program.DoRun(String[] args)
        il2cpp.Program.Run(String[] args)
         il2cpp.Program.Main(String[] args)
        ---> (Exception interne #0) System.ComponentModel.Win32Exception (0x80004005): L'ex?cutable sp?cifi? n'est pas une application valide pour cette plateforme de syst?me d'exploitation.
        ....


    2error
        Exception: C:\Program Files\Unity\Hub\Editor\2019.2.0f1\Editor\Data\il2cpp/build/il2cpp.exe did not run properly!
        UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:128)
        UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:71)
        UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo, System.String workingDirectory) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:502)
        UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (System.String inputDirectory, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:483)
        UnityEditorInternal.IL2CPPBuilder.Run () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:334)
        UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:63)
        UnityEditor.Android.PostProcessor.Tasks.RunIl2Cpp.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <8277255796414cc8b8865316c1676de5>:0)
        UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <8277255796414cc8b8865316c1676de5>:0)
        UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <8277255796414cc8b8865316c1676de5>:0)
        UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <8277255796414cc8b8865316c1676de5>:0)
        UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:281)
        UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)


Solution 1:[1]

I solved this problem but my platform is on Mac. This may be helpful for you.

I downloaded NDK r16b from Google but found it was very different from Unity Hub. Because many files and folders were missing. Also, the detail settings of Unity won't point NDK to the right place. So I used Unity Hub to download r16b and manually set it up.

Then it worked with Unity 2019 1.14f and 2019 2.14f.

Suggestion:

  • Download NDK by Unity Hub
  • Manually set NDK's path in Unity

Solution 2:[2]

Use Android NDK r16b and set its path in Unity Editor.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eric Wei
Solution 2