Unity很早就提供了Android il2cpp的編譯接口,謠傳il2cpp效率提升了一些,讓出了一些效率給渲染。還有一個好處破解難度升級,mono時代反編譯dll就好,il2cpp的.so文件破解難度增加。最近反編譯大廠的游戲很多游戲也開始使用il2cpp
但是如果項目第一次編譯il2cpp可能會報錯,報錯如下
Failed running D:\Unity562p4\Editor\Data\il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --development-mode --compile-cpp --libil2cpp-static --platform="Android"
這句話仔細看可以看到C#中的方法
D:\Unity_WorkSpace\xxxx\trunk\code\client\goe\client\project\Temp\StagingArea\Il2Cpp\il2cppOutput/Bulk_Assembly-CSharp_14.cpp:14225: undefined reference to `IsiOSFunc' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
其實是因為初步轉il2cpp,iOSSDK的一些方法在Android平台沒有,例如估下方法
[DllImport("__Internal")] private static extern bool IsiOSFunc();
以[DllImport(“__Internal”)]修飾的方法必須在對應平台有對應的c++實現不然就報錯
所以可以使用宏修飾該方法
#if UNITY_IOS && !UNITY_EDITOR [DllImport("__Internal")] private static extern bool IsiOSFunc(); #endif
這下Android il2cpp編譯就通過了