IL2CPP build error on Android and iOS in 2019.3.1f, but no errors in 2019.2.1f1

In our project we use the ElasticSearch .Net library.
We have tested it for both platforms: Android and iOS using Unity 2019.2.1f1
Now we try to switch to Unity 2019.3.1f1. If we compile the iOS project we get build errors:

I was able to reproduce this error on empty project just with Elasticsearch.dll also for Android IL2CPP. (see attachment) This project compiles successfully for Android IL2CPP in Unity 2019.2.1f1, but does not compile in 2019.3.1f1

Steps to reproduce:

  1. Open the project in Unity 2019.2.1f1
  2. Switch to Android
  3. Select IL2CPP Scripting backend in Player Settings
  4. Try to build
  5. See that the build was successful
  6. Close the project
  7. Delete all folders/files inside project folder except of Assets folder
  8. Open the project in Unity 2019.3.1f1
  9. Switch to Android
  10. Select IL2CPP Scripting backend in Player Settings
  11. Try to build
  12. See error message:

5489412–562443–ElasticSearchIL2CPPError.zip (1.57 MB)

1 Like

Hello dear Unity team! This problem is still actual.

I had a similar issue with the il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile. Here is how I fixed the issue and got both an apk and appbundle to build (though this seems not to work for every project) →

-First, I changed the SDK and NDK locations - went to Edit->Preferences->uncheck the suggested unity path to both SDK and NDK and copy the file path where unity stores both of them.

-paste a copy of both the sdk and NDK into your downloads folder on C drive

-go back to Editor → preferences-> Click browse next to sdk and ndk paths-> Navigate to a copy of both the SDK and NDK in C:\Users\yourUserName\Downloads\NDK and C:\Users\yourUserName\Downloads\sdk

-Go to window->package manager and unistall/remove In-App purchases plugin.

I have seen many people approach this problem in different ways on these forums, but this one worked for me.
Best of luck. :slight_smile:

Hey, thanks for your answer. I tried it out, it does not help. :frowning:

I think the problem is in IL2CPP tool that comes with Unity 2019.3, not in the Android SDK or NDK. This is also actual for the iOS build.
As we see from the log an unhandled exception occurs in the IL2CPP tool, it can not find a GetEnumerator() method in their internal dictionary for types.

In the Elasticsearch.Net is a dictionary declaration:

[JsonFormatter(typeof(DynamicDictionaryFormatter))]
public class DynamicDictionary : DynamicObject, IEquatable<DynamicDictionary>, IEnumerable<string>, IEnumerable, IDictionary<string, DynamicValue>, ICollection<KeyValuePair<string, DynamicValue>>, IEnumerable<KeyValuePair<string, DynamicValue>>
{
    private readonly IDictionary<string, DynamicValue> _backingDictionary = new Dictionary<string, DynamicValue>(StringComparer.OrdinalIgnoreCase);
    ...
  
    IEnumerator<KeyValuePair<string, DynamicValue>> IEnumerable<KeyValuePair<string, DynamicValue>>.GetEnumerator()
    {
        return _backingDictionary.GetEnumerator();
    }
    ...
}

The DynamicValue is a class that can be converted to pretty all C# types:

public class DynamicValue : DynamicObject, IEquatable<DynamicValue>, IConvertible
{
    private readonly object _value;
    ...
}

I have two copies of the test project attached to my previous post (zip file). One is opened in Unity 2019.2, another in Unity 2019.3.
I’ve done all the steps described in my previous post. Now I compare IL2CPP output folders.
So, if we compare the IL2CPP output folders (<project_folder>\Temp\StagingArea\Il2Cpp\il2cppOutput) in Unity 2019.2 and 2019.3 we see that the DynamicValue has no implementation in 2019.3 version.
Here is Unity 2019.2 IL2CPP output (Elasticsearch.Net.cpp file):

...
// Elasticsearch.Net.DynamicValue
struct  DynamicValue_tF1C23C3A41C94C69BF21A2CC2B4409646107C876  : public DynamicObject_t61C899E96C95A40CEFBA36DE860005C26D12FBB0
{
public:
    // System.Object Elasticsearch.Net.DynamicValue::_value
    RuntimeObject * ____value_0;

public:
    inline static int32_t get_offset_of__value_0() { return static_cast<int32_t>(offsetof(DynamicValue_tF1C23C3A41C94C69BF21A2CC2B4409646107C876, ____value_0)); }
    inline RuntimeObject * get__value_0() const { return ____value_0; }
    inline RuntimeObject ** get_address_of__value_0() { return &____value_0; }
    inline void set__value_0(RuntimeObject * value)
    {
        ____value_0 = value;
        Il2CppCodeGenWriteBarrier((void**)(&____value_0), (void*)value);
    }
};
...

and here is the Unity 2019.3 IL2CPP output (Elasticsearch.Net.cpp file):

...
// Elasticsearch.Net.DynamicValue
struct  DynamicValue_tF1C23C3A41C94C69BF21A2CC2B4409646107C876  : public DynamicObject_t61C899E96C95A40CEFBA36DE860005C26D12FBB0
{
public:

public:
};
...

if we keep comparing the files, we will see that there is no

DynamicDictionary_Equals_m7A79E3977FFE0AD9BE8933450848C15E8D078A5F,
DynamicDictionary_Equals_m50FF6739CA43ED5E77D8BDD9E67B66D21E720DDD,
DynamicDictionary_GetHashCode_m42EF3EACA354895E84815CD675C7C2AC81D08553,
DynamicDictionary_GetNeutralKey_m3B3C34EB7A00B6398D292B406ED128FF5378C298

methods implementation in the Unity 2019.3 version.

It seems to me that something was changed in the IL2CPP tool, what breaks the build in Unity 2019.3 version. I assume that the problem is not only with the Elasticsearch dll, users can write own code that builds in Unity 2019.2 and does not build in 2019.3.

This problem is still actual. Need help!

1 Like

Can you submit a bug report for this issue? We would like to investigate it.

1 Like

Thanks for your reply! I’ve submitted a bug through Unity 2019.3.1f1 editor.
(Case 1222808) IL2CPP build error on Android and iOS in 2019.3.1f, but no errors in 2019.2.1f1

1 Like

I’ve installed Unity 2019.3.3f1 version and tried to build the sample project from my first message.
It does not build.
Here is the log message (looks pretty the same as in Unity 2019.3.1f1 version):

Thanks for the update. We’ve not corrected this issue yet.

1 Like

How to correct this issue?please tell me way to do this. I am really stuck here from a long time and still not able to build on Ill2cpp.

I’m not sure yet. It looks like our QA team closed the issue, but I think it might be a real problem that we should investigate. I’ve re-opened the issue and asked our QA team to have another look.

2 Likes

Thank you very much for drawing your attention to this. I am in real trouble for this, I am not able to get a build. Please tell me how can I get rid of this problem.

We will need to investigate it before I can offer any advice, sorry.

1 Like

@JoshPeterson I’m having also this issue, I tried with 2019.3.07a and with 2019.4.1f1 and gives in both the same errors, I’ll attach you the console, Im using default unity’s NDK, SDK and JDK in a windows 10 PC:

Failed running C:\Program Files\Unity\Hub\Editor\2019.4.1f1\Editor\Data\il2cpp/build/deploy/net471/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=“D:\Unity\New Unity Project\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a\libil2cpp.so” --cachedirectory=“D:\Unity\New Unity Project\Assets..\Library\il2cpp_android_armeabi-v7a/il2cpp_cache” --additional-include-directories=“C:/Program Files/Unity/Hub/Editor/2019.4.1f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\bdwgc/include” --additional-include-directories=“C:/Program Files/Unity/Hub/Editor/2019.4.1f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\libil2cpp/include” --tool-chain-path=“C:/Program Files/Unity/Hub/Editor/2019.4.1f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK” --profiler-report --map-file-parser=“C:/Program Files/Unity/Hub/Editor/2019.4.1f1/Editor/Data/Tools/MapFileParser/MapFileParser.exe” --directory=“D:/Unity/New Unity Project/Temp/StagingArea/assets/bin/Data/Managed” --generatedcppdir=“D:/Unity/New Unity Project/Temp/StagingArea/Il2Cpp/il2cppOutput”

stdout:
Building libil2cpp.so with AndroidToolChain
Output directory: D:\Unity\New Unity Project\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a
Cache directory: D:\Unity\New Unity Project\Library\il2cpp_android_armeabi-v7a\il2cpp_cache
ObjectFiles: 113 of which compiled: 113
Time Compile: 10071 milliseconds Lump_libil2cpp_vm.cpp
Time Compile: 8784 milliseconds mscorlib8.cpp
Time Compile: 7746 milliseconds mscorlib7.cpp
Time Compile: 6925 milliseconds UnityEngine.UI.cpp
Time Compile: 6536 milliseconds Lump_libil2cpp_icalls.cpp
Time Compile: 5388 milliseconds Il2CppTypeDefinitions.c
Time Compile: 5262 milliseconds mscorlib3.cpp
Time Compile: 4936 milliseconds Generics5.cpp
Time Compile: 4732 milliseconds Generics1.cpp
Time Compile: 4663 milliseconds Il2CppInvokerTable.cpp
Total compilation time: 39738 milliseconds.
il2cpp.exe didn’t catch exception: Unity.IL2CPP.Building.BuilderFailedException: C:\Program Files\Unity\Hub\Editor\2019.4.1f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @“C:\Users\elnan\AppData\Local\Temp\tmp25F6.tmp” -o “D:\Unity\New Unity Project\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_E764FEB763DC20D759253AC330607842\libil2cpp.so” -shared -Wl,-soname,libil2cpp.so -Wl,–no-undefined -Wl,-z,noexecstack -Wl,–gc-sections -Wl,–build-id -stdlib=libc++ -static-libstdc++ -target armv7-linux-androideabi19 -Wl,–wrap,sigaction -llog -rdynamic -fuse-ld=gold.exe

D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7328: error: undefined reference to ‘SyncFiles’
D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7342: error: undefined reference to ‘WindowAlert’
D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7328: error: undefined reference to ‘SyncFiles’
D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7342: error: undefined reference to ‘WindowAlert’
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

en Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet1 objectFiles, CppToolChainContext toolChainContext) en Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics) en il2cpp.Program.DoRun(String[ ] args, List1 foundAssemblies)
en il2cpp.Program.Run(String[ ] args, Boolean setInvariantCulture)
en il2cpp.Program.Main(String[ ] args)
stderr:

Excepci�n no controlada: Unity.IL2CPP.Building.BuilderFailedException: C:\Program Files\Unity\Hub\Editor\2019.4.1f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @“C:\Users\elnan\AppData\Local\Temp\tmp25F6.tmp” -o “D:\Unity\New Unity Project\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_E764FEB763DC20D759253AC330607842\libil2cpp.so” -shared -Wl,-soname,libil2cpp.so -Wl,–no-undefined -Wl,-z,noexecstack -Wl,–gc-sections -Wl,–build-id -stdlib=libc++ -static-libstdc++ -target armv7-linux-androideabi19 -Wl,–wrap,sigaction -llog -rdynamic -fuse-ld=gold.exe

D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7328: error: undefined reference to ‘SyncFiles’
D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7342: error: undefined reference to ‘WindowAlert’
D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7328: error: undefined reference to ‘SyncFiles’
D:\Unity\New Unity Project\Temp\StagingArea\Il2Cpp\il2cppOutput/Assembly-CSharp.cpp:7342: error: undefined reference to ‘WindowAlert’
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

en Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet1 objectFiles, CppToolChainContext toolChainContext) en Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics) en il2cpp.Program.DoRun(String[ ] args, List1 foundAssemblies)
en il2cpp.Program.Run(String[ ] args, Boolean setInvariantCulture)
en il2cpp.Program.Main(String[ ] args)

UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase)
UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action1) UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List1, Action1, String) UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(Il2CppBuildPipelineData, String, String, Boolean) UnityEditorInternal.IL2CPPBuilder:Run() UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action1, RuntimeClassRegistry)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

2 console message:
Exception: C:\Program Files\Unity\Hub\Editor\2019.4.1f1\Editor\Data\il2cpp/build/deploy/net471/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 :0)
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action1[T] setupStartInfo) (at <a0a9ad37e16b4f7cb955e1101b72d4cc>:0) UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List1[T] arguments, System.Action1[T] setupStartInfo, System.String workingDirectory) (at <a0a9ad37e16b4f7cb955e1101b72d4cc>:0) UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at <a0a9ad37e16b4f7cb955e1101b72d4cc>:0) UnityEditorInternal.IL2CPPBuilder.Run () (at <a0a9ad37e16b4f7cb955e1101b72d4cc>:0) UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at :0)
UnityEditor.Android.PostProcessor.Tasks.RunIl2Cpp.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :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 :0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at :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 :0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Last message:
UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002bb] in :0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in :0
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

This failure occurs because the code in the project has extern methods in C#. Methods marked as extern with a the [Dllimport(“__Internal”)] attribute must be present in a native library that is linked with the Unity player when building with the IL2CPP scripting backend.

For example, this in this project one function which causes this issue is named: SyncFiles

You have two options:

  1. Build a native library with all of the methods marked as extern with the [Dllimport(“__Internal”)] attribute for the target platform and architecture of the player. See this documentation for details about native plugins: https://docs.unity3d.com/Manual/NativePlugins.html

  2. Remove the C# code which defines this extern method. You can do that with platform dependent compilation: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html