I wanted to optimize the size of my .apk file by exporting the scene I needed and import it to a clean project. All was fine no errors found in my project but it failed to build.
Exception: Unity.IL2CPP.Building.BuilderFailedException: C:\UnityReq\android-ndk-r19\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @“C:\Users\ALI\AppData\Local\Temp\tmp1D32.tmp” -o “C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_7FB29020877A26EBC0E1CD0068F36D23\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 “C:\Program Files\UnityEditor\2020.3.16f1\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\il2cpp\Release\StaticLibs\armeabi-v7a\baselib.a” -llog -rdynamic -fuse-ld=gold.exe
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55025: error: undefined reference to ‘UnityMC_Delegate_getEnabled’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55025: error: undefined reference to ‘UnityMC_Delegate_getEnabled’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55016: error: undefined reference to ‘UnityMC_Delegate_setEnabled’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55016: error: undefined reference to ‘UnityMC_Delegate_setEnabled’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54976: error: undefined reference to ‘UnityMC_Delegate_initWithName’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54976: error: undefined reference to ‘UnityMC_Delegate_initWithName’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54966: error: undefined reference to ‘UnityMC_Delegate_sendToAllPeers’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54966: error: undefined reference to ‘UnityMC_Delegate_sendToAllPeers’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54986: error: undefined reference to ‘UnityMC_Delegate_receivedDataQueueSize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54986: error: undefined reference to ‘UnityMC_Delegate_receivedDataQueueSize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54996: error: undefined reference to ‘UnityMC_Delegate_dequeueReceivedData’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54996: error: undefined reference to ‘UnityMC_Delegate_dequeueReceivedData’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55006: error: undefined reference to ‘UnityMC_Delegate_connectedPeerCount’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55006: error: undefined reference to ‘UnityMC_Delegate_connectedPeerCount’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:54986: error: undefined reference to ‘UnityMC_Delegate_receivedDataQueueSize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp1.cpp:55006: error: undefined reference to ‘UnityMC_Delegate_connectedPeerCount’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35807: error: undefined reference to ‘UnityMC_NSData_getLength’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35807: error: undefined reference to ‘UnityMC_NSData_getLength’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35827: error: undefined reference to ‘UnityMC_NSData_createWithBytes’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35827: error: undefined reference to ‘UnityMC_NSData_createWithBytes’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35837: error: undefined reference to ‘UnityMC_NSData_createWithBytesNoCopy’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35837: error: undefined reference to ‘UnityMC_NSData_createWithBytesNoCopy’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35817: error: undefined reference to ‘UnityMC_NSData_getBytes’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35807: error: undefined reference to ‘UnityMC_NSData_getLength’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:35817: error: undefined reference to ‘UnityMC_NSData_getBytes’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36748: error: undefined reference to ‘UnityMC_CFRelease’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36151: error: undefined reference to ‘UnityMC_NSError_code’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36161: error: undefined reference to ‘UnityMC_NSError_localizedDescription’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36748: error: undefined reference to ‘UnityMC_CFRelease’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36151: error: undefined reference to ‘UnityMC_NSError_code’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36161: error: undefined reference to ‘UnityMC_NSError_localizedDescription’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36670: error: undefined reference to ‘UnityMC_NSString_lengthOfBytesUsingEncoding’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36690: error: undefined reference to ‘UnityMC_NSString_getBytes’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36680: error: undefined reference to ‘UnityMC_NSString_getLength’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36660: error: undefined reference to ‘UnityMC_NSString_createWithString’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36660: error: undefined reference to ‘UnityMC_NSString_createWithString’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36710: error: undefined reference to ‘UnityMC_NSString_deserialize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36710: error: undefined reference to ‘UnityMC_NSString_deserialize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36680: error: undefined reference to ‘UnityMC_NSString_getLength’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36680: error: undefined reference to ‘UnityMC_NSString_getLength’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36670: error: undefined reference to ‘UnityMC_NSString_lengthOfBytesUsingEncoding’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36690: error: undefined reference to ‘UnityMC_NSString_getBytes’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36700: error: undefined reference to ‘UnityMC_NSString_serialize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36700: error: undefined reference to ‘UnityMC_NSString_serialize’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36748: error: undefined reference to ‘UnityMC_CFRelease’
C:\Project\Fork\RotaryDryerLightOne\RotaryDryerLightOne\Library\Il2cppBuildCache\Android\armeabi-v7a\il2cppOutput/Assembly-CSharp2.cpp:36680: error: undefined reference to ‘UnityMC_NSString_getLength’
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(HashSet1 objectFiles, CppToolChainContext toolChainContext) at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics) at il2cpp.Compilation.CompilationDriver.Run(RuntimePlatform platform, BuildingOptions buildingOptions, ReadOnlyCollection1 matchedAssemblyMethodSourceFiles)
at il2cpp.Program.DoRun(String[ ] args, RuntimePlatform platform, BuildingOptions buildingOptions, Boolean throwExceptions)
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 <ef3b6bf002d8435a97b4e938f6c49b02>:0) UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List1[T] arguments, System.Action1[T] setupStartInfo) (at <ef3b6bf002d8435a97b4e938f6c49b02>:0) UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data) (at <ef3b6bf002d8435a97b4e938f6c49b02>:0) UnityEditorInternal.IL2CPPBuilder.Run () (at <ef3b6bf002d8435a97b4e938f6c49b02>: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, Boolean&)
I did some googling and found that I have to remove the il2cpp things in my library folder but it won’t work.
Any help will be appreciated. Thanks!
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: UnityMC_Delegate_getEnabled
You have two options:
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: Unity - Manual: Native plug-ins
Remove the C# code which defines this extern method. You can do that with platform dependent compilation: Unity - Manual: Conditional compilation
Thanks for your help! I’m not sure which one to remove but you mentioned UnityMC_Delegate_getEnabled and then I googled it and I found this . He mentioned about the multipeer folder and it’s related to iOS so I did this to every scripts which has DllImport inside it.
#if UNITY_IOS || UNITY_EDITOR
[DllImport(“__Internal”, EntryPoint=“UnityMC_NSString_createWithString”)]
static extern IntPtr CreateWithString([MarshalAs(UnmanagedType.LPWStr)] string text, int length);
[DllImport(“__Internal”, EntryPoint=“UnityMC_NSString_lengthOfBytesUsingEncoding”)]
static extern int GetLengthOfBytes(NSString self);
[DllImport(“__Internal”, EntryPoint=“UnityMC_NSString_getLength”)]
static extern int GetLength(NSString self);
[DllImport(“__Internal”, EntryPoint=“UnityMC_NSString_getBytes”)]
static extern unsafe bool GetBytes(NSString self, void* buffer, int length);
[DllImport(“__Internal”, EntryPoint=“UnityMC_NSString_serialize”)]
static extern NSData Serialize(NSString self);
[DllImport(“__Internal”, EntryPoint=“UnityMC_NSString_deserialize”)]
static extern IntPtr Deserialize(NSData data);
#endif
But it gives me some error like below when I build it
Seems like it tries to compile but can’t find the code.
I also tried to just removed it. It build successfully but when I tried it, the screen is black but the system actually tracking the surface because the points showed up and I can tap it to show the object.
*EDIT
I changed to this and the errors gone.
#if UNITY_IOS
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_sendToAllPeers”)]
static extern NSError SendToAllPeers(MCSession self, NSData data, MCSessionSendDataMode mode);
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_initWithName”)]
static extern IntPtr InitWithName(NSString name, NSString serviceType);
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_receivedDataQueueSize”)]
static extern int GetReceivedDataQueueSize(MCSession self);
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_dequeueReceivedData”)]
static extern NSData DequeueReceivedData(MCSession self);
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_connectedPeerCount”)]
static extern int GetConnectedPeerCount(MCSession self);
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_setEnabled”)]
static extern void SetEnabled(MCSession self, bool enabled);
[DllImport(“__Internal”, EntryPoint=“UnityMC_Delegate_getEnabled”)]
static extern bool GetEnabled(MCSession self);
#else
[DllImport(“UnityMC_Delegate_sendToAllPeers”)]
static extern NSError SendToAllPeers(MCSession self, NSData data, MCSessionSendDataMode mode);
[DllImport(“UnityMC_Delegate_initWithName”)]
static extern IntPtr InitWithName(NSString name, NSString serviceType);
[DllImport(“UnityMC_Delegate_receivedDataQueueSize”)]
static extern int GetReceivedDataQueueSize(MCSession self);
[DllImport(“UnityMC_Delegate_dequeueReceivedData”)]
static extern NSData DequeueReceivedData(MCSession self);
[DllImport(“UnityMC_Delegate_connectedPeerCount”)]
static extern int GetConnectedPeerCount(MCSession self);
[DllImport(“UnityMC_Delegate_setEnabled”)]
static extern void SetEnabled(MCSession self, bool enabled);
[DllImport(“UnityMC_Delegate_getEnabled”)]
static extern bool GetEnabled(MCSession self);
#endif
But still black screen when I tried it.