Unity version 5.6.6 f2

When using IL2CPP on Android, an error is reported as follows:

stdout: IL2CPP error (no further information about what managed code was being converted is available) Additional information: ����ʵ� il2cpp. Exe didn't catch exception: System.NullReferenceException: The delta � � � � � � � � � � � � � o � � � � � � � ʵ � � � � � � Unity. IL2CPP. Extensions. GetBaseType (TypeReference TypeReference) � � Unity. IL2CPP. GenericSharing. GenericSharingVisitor. AddStaticUsageRecursiveIfNeeded (TypeReference genericType) � � Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Process(Instruction instruction, MethodDefinition method) � � Unity. IL2CPP. GenericSharing. GenericSharingVisitor. ProcessType (TypeDefinition type) � � Unity. IL2CPP. GenericSharing. GenericSharingVisitor. Collect (AssemblyDefinition assembly) � � Unity.IL2CPP.AssemblyConverter.PreProcessStage(IInteropDataCollector interopDataCollector, ReadOnlyInflatedCollectionCollector& readOnlyGenericsCollectionCollector, TypeDefinition [] & allTypeDefinitions) � � Unity. IL2CPP. AssemblyConverter. The Apply () � � Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(NPath[] assemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder) � � Unity. IL2CPP. AssemblyConverter. ConvertAssemblies (IEnumerable ` 1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder) �� il2cpp.program.dorun (String[] args) �� il2cpp.program.run (String[] args) �� Il2cpp. The Program. The Main (String [] args) stderr: delta � � � � � � � � � 쳣 : System. NullReferenceException: The delta � � � � � � � � � � � � � o � � � � � � � ʵ � � � � � � Unity. IL2CPP. Extensions. GetBaseType (TypeReference TypeReference) � � Unity. IL2CPP. GenericSharing. GenericSharingVisitor. AddStaticUsageRecursiveIfNeeded (TypeReference genericType) � � Unity.IL2CPP.GenericSharing.GenericSharingVisitor.Process(Instruction instruction, MethodDefinition method) � � Unity. IL2CPP. GenericSharing. GenericSharingVisitor. ProcessType (TypeDefinition type) � � Unity. IL2CPP. GenericSharing. GenericSharingVisitor. Collect (AssemblyDefinition assembly) � � Unity.IL2CPP.AssemblyConverter.PreProcessStage(IInteropDataCollector interopDataCollector, ReadOnlyInflatedCollectionCollector& readOnlyGenericsCollectionCollector, TypeDefinition [] & allTypeDefinitions) � � Unity. IL2CPP. AssemblyConverter. The Apply () � � Unity.IL2CPP.AssemblyConverter.ConvertAssemblies(NPath[] assemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder) � � Unity. IL2CPP. AssemblyConverter. ConvertAssemblies (IEnumerable ` 1 assemblyDirectories, IEnumerable`1 explicitAssemblies, NPath outputDir, NPath dataFolder, NPath symbolsFolder) �� il2cpp.program.dorun (String[] args) �� il2cpp.program.run (String[] args) �� il2cpp.Program.Main(String[] args) UnityEngine.Debug:LogError(Object) UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:96) UnityEditorInternal.IL2CPPBuilder:RunIl2CppWithArguments(List`1, Action`1, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:313) UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(ICollection`1, String, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:304) UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:151) UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry, Boolean) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:34) UnityEditor.HostView:OnGUI()Copy the code

From the error message, it is an empty reference exception, but it does not indicate the specific location of the error. In addition, IL2CPP compilation through other project tests is normal, indicating that there is a problem with the current project code. There is a method to locate the specific error through elimination, and finally locate it in the code, as follows:

static bool IsIosDeviceHighEnd()
{
    string generation = UnityEngine.iOS.Device.generation.ToString().ToLower();
    return list.Contains(generation);
}
Copy the code

Although this method will not be called under Android, it is still compiled. Unityengine.ios.Device is a special function interface of iOS system, and there is no corresponding C++ implementation of IL2CPP in Android, so the compilation error is caused.

Here you can control compilation by adding macros, as follows

#if UNITY_IOS
static bool IsIosDeviceHighEnd()
{
    string generation = UnityEngine.iOS.Device.generation.ToString().ToLower();
    return list.Contains(generation);
}
#endif
Copy the code

If you encounter an IL2CPP compilation error later, you can check to see if it contains a method interface that is not implemented on Android.