Unity Android Build 在 Mono 中工作,但由于未定义的引用、缺少库而在 IL2CPP 中失败

如何解决Unity Android Build 在 Mono 中工作,但由于未定义的引用、缺少库而在 IL2CPP 中失败

我正在尝试更新我们在 Google Play 商店中存在多年的基于 artoolkit5 的 Unity Android 应用。 artoolkit5 不再受支持,但我们仍然依赖其大约 4 年前构建的库。我的Unity版本是2020.1.11f1。

我需要将应用升级到 Google App Bundle 并添加 64 位支持。所以我理解,第一步是从 Mono 更改为 IL2CPP 作为脚本后端。 32 位 Android ARMv7 应用程序在 Mono 中构建并且运行良好,但是当我实际上只进行一项更改时,即在项目设置下切换到 IL2CPP 作为脚本后端时,构建失败。我什至还没有尝试添加 ARM64 选项。

使用 IL2CPP 时,构建失败,出现 BuilderFailedException 和数百个 Undefined References...

Exception: /Applications/2020.1.11f1/Unity.app/Contents/il2cpp/build/deploy/net471/il2cpp.exe did not run properly!

Failed running "/Applications/2020.1.11f1/Unity.app/Contents/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="<redacted>/Temp/StagingArea/assets/bin/Data/Native/armeabi-v7a/libil2cpp.so" --cachedirectory="<redacted>/Assets/../Library/il2cpp_android_armeabi-v7a/il2cpp_cache" --additional-include-directories="/Applications/2020.1.11f1/PlaybackEngines/Androidplayer/Tools/bdwgc/include" --additional-include-directories="/Applications/2020.1.11f1/PlaybackEngines/Androidplayer/Tools/libil2cpp/include" --baselib-directory="/Applications/2020.1.11f1/PlaybackEngines/Androidplayer/Variations/il2cpp/Release/StaticLibs/armeabi-v7a" --avoid-dynamic-library-copy --tool-chain-path="/Applications/2020.1.11f1/PlaybackEngines/Androidplayer/NDK" --profiler-report --map-file-parser="/Applications/2020.1.11f1/Unity.app/Contents/Tools/MapFileParser/MapFileParser" --directory="<redacted>/Temp/StagingArea/assets/bin/Data/Managed" --generatedcppdir="<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput"  

stdout:
Running il2cpp.exe in workstation GC mode.
Building libil2cpp.so with AndroidToolChain
    Output directory: <redacted>/Temp/StagingArea/assets/bin/Data/Native/armeabi-v7a
    Cache directory: <redacted>/Library/il2cpp_android_armeabi-v7a/il2cpp_cache
ObjectFiles: 186 of which compiled: 0
Total compilation time: 157 milliseconds.
il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: /Applications/2020.1.11f1/PlaybackEngines/Androidplayer/NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ @"/var/folders/vc/9b7436817vzgvxlqrftcl1nr0000gn/T/tmp1b926095.tmp" -o "<redacted>/Library/il2cpp_android_armeabi-v7a/il2cpp_cache/linkresult_01F24D8C43A06CD45FA9C75071D0A3D6/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 "/Applications/2020.1.11f1/PlaybackEngines/Androidplayer/Variations/il2cpp/Release/StaticLibs/armeabi-v7a/baselib.a" -llog -rdynamic -fuse-ld=gold

<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28131: error: undefined reference to 'arwRegisterLogCallback'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28140: error: undefined reference to 'arwSetLogLevel'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28149: error: undefined reference to 'arwInitialiseAR'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28159: error: undefined reference to 'arwInitialiseARWithOptions'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28173: error: undefined reference to 'arwGetartoolkitVersion'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28190: error: undefined reference to 'arwGetError'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28200: error: undefined reference to 'arwShutdownAR'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28221: error: undefined reference to 'arwStartRunningB'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28235: error: undefined reference to 'arwIsRunning'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28245: error: undefined reference to 'arwStopRunning'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28262: error: undefined reference to 'arwGetProjectionMatrix'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28276: error: undefined reference to 'arwGetVideoParams'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28293: error: undefined reference to 'arwCapture'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28303: error: undefined reference to 'arwUpdateAR'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28313: error: undefined reference to 'arwUpdateTexture32'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28323: error: undefined reference to 'arwGetMarkerPatternCount'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28340: error: undefined reference to 'arwGetMarkerPatternConfig'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28357: error: undefined reference to 'arwGetMarkerPatternImage'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28367: error: undefined reference to 'arwGetMarkerOptionBool'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28377: error: undefined reference to 'arwSetMarkerOptionBool'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28386: error: undefined reference to 'arwGetMarkerOptionInt'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28396: error: undefined reference to 'arwSetMarkerOptionInt'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28405: error: undefined reference to 'arwGetMarkerOptionFloat'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28415: error: undefined reference to 'arwSetMarkerOptionFloat'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28424: error: undefined reference to 'arwSetVideoDebugMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28433: error: undefined reference to 'arwGetVideoDebugMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28443: error: undefined reference to 'arwSetVideoThreshold'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28452: error: undefined reference to 'arwGetVideoThreshold'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28462: error: undefined reference to 'arwSetVideoThresholdMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28471: error: undefined reference to 'arwGetVideoThresholdMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28481: error: undefined reference to 'arwSetLabelingMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28490: error: undefined reference to 'arwGetLabelingMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28500: error: undefined reference to 'arwSetBorderSize'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28509: error: undefined reference to 'arwGetBorderSize'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28519: error: undefined reference to 'arwSetPatternDetectionMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28528: error: undefined reference to 'arwGetPatternDetectionMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28538: error: undefined reference to 'arwSetMatrixCodeType'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28547: error: undefined reference to 'arwGetMatrixCodeType'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28557: error: undefined reference to 'arwSetimageProcMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28566: error: undefined reference to 'arwGetimageProcMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28576: error: undefined reference to 'arwSetNFTMultiMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28585: error: undefined reference to 'arwGetNFTMultiMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28599: error: undefined reference to 'arwAddMarker'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28613: error: undefined reference to 'arwRemoveMarker'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28623: error: undefined reference to 'arwRemoveAllMarkers'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28633: error: undefined reference to 'arwQueryMarkerVisibility'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28650: error: undefined reference to 'arwQueryMarkerTransformation'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28685: error: undefined reference to 'arwLoadOpticalParams'
clang++: error: linker command Failed with exit code 1 (use -v to see invocation)


  at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles (System.Collections.Generic.HashSet`1[T] objectFiles,Unity.IL2CPP.Building.ToolChains.CppToolChainContext toolChainContext) [0x00203] in <bb3d372ae2c942d1b47f060d5cd89a4d>:0 
  at Unity.IL2CPP.Building.CppProgramBuilder.Build (Unity.IL2CPP.Building.Statistics.IBuildStatistics& statistics) [0x0025c] in <bb3d372ae2c942d1b47f060d5cd89a4d>:0 
  at Unity.IL2CPP.Building.Statistics.BuildingTestRunnerHelper.BuildAndLogStatsForTestRunner (Unity.IL2CPP.Building.CppProgramBuilder builder,Unity.IL2CPP.Building.Statistics.IBuildStatistics& statistics) [0x00000] in <bb3d372ae2c942d1b47f060d5cd89a4d>:0 
  at il2cpp.Compilation.CompilationDriver.Run (Unity.IL2CPP.Common.RuntimePlatform platform,Unity.IL2CPP.Building.BuildingOptions buildingOptions) [0x001fd] in <3be9f628f5fa469389bd6a91a579ba8a>:0 
  at il2cpp.Program.DoRun (System.String[] args,Unity.IL2CPP.Common.RuntimePlatform platform,Unity.IL2CPP.Building.BuildingOptions buildingOptions) [0x0001f] in <3be9f628f5fa469389bd6a91a579ba8a>:0 
  at il2cpp.Program.Run (System.String[] args,System.Boolean setInvariantCulture) [0x00063] in <3be9f628f5fa469389bd6a91a579ba8a>:0 
  at il2cpp.Program.Main (System.String[] args) [0x00000] in <3be9f628f5fa469389bd6a91a579ba8a>:0 
stderr:

Unhandled Exception:
Unity.IL2CPP.Building.BuilderFailedException: /Applications/2020.1.11f1/PlaybackEngines/Androidplayer/NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ @"/var/folders/vc/9b7436817vzgvxlqrftcl1nr0000gn/T/tmp1b926095.tmp" -o "<redacted>/Library/il2cpp_android_armeabi-v7a/il2cpp_cache/linkresult_01F24D8C43A06CD45FA9C75071D0A3D6/libil2cpp.so" -shared -Wl,sigaction "/Applications/2020.1.11f1/PlaybackEngines/Androidplayer/Variations/il2cpp/Release/StaticLibs/armeabi-v7a/baselib.a" -llog -rdynamic -fuse-ld=gold

<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28131: error: undefined reference to 'arwRegisterLogCallback'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28140: error: undefined reference to 'arwSetLogLevel'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28149: error: undefined reference to 'arwInitialiseAR'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28159: error: undefined reference to 'arwInitialiseARWithOptions'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28173: error: undefined reference to 'arwGetartoolkitVersion'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28190: error: undefined reference to 'arwGetError'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28200: error: undefined reference to 'arwShutdownAR'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28221: error: undefined reference to 'arwStartRunningB'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28235: error: undefined reference to 'arwIsRunning'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28245: error: undefined reference to 'arwStopRunning'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28262: error: undefined reference to 'arwGetProjectionMatrix'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28276: error: undefined reference to 'arwGetVideoParams'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28293: error: undefined reference to 'arwCapture'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28303: error: undefined reference to 'arwUpdateAR'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28313: error: undefined reference to 'arwUpdateTexture32'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28323: error: undefined reference to 'arwGetMarkerPatternCount'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28340: error: undefined reference to 'arwGetMarkerPatternConfig'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28357: error: undefined reference to 'arwGetMarkerPatternImage'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28367: error: undefined reference to 'arwGetMarkerOptionBool'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28377: error: undefined reference to 'arwSetMarkerOptionBool'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28386: error: undefined reference to 'arwGetMarkerOptionInt'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28396: error: undefined reference to 'arwSetMarkerOptionInt'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28405: error: undefined reference to 'arwGetMarkerOptionFloat'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28415: error: undefined reference to 'arwSetMarkerOptionFloat'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28424: error: undefined reference to 'arwSetVideoDebugMode'
<redacted>/Temp/StagingArea/Il2Cpp/il2cppOutput/Assembly-CSharp.cpp:28433: error: undefined referen<message truncated>

认为的意思是链接器找不到列出的函数的定义,所有这些定义都来自一个 artoolkit 库:libARWrapper.so

此库存在于 Unity 项目中:Assets/Plugins/Android/lib/armeabi-v7a/libARWrapper.so

在 Unity Inspector 中快速检查显示库导入设置似乎是正确的。

Unity Inspector: libARWrapper.so Import Settings

这似乎表明该库将包含在 Android ARMv7 版本中,就是这样。而且我知道该库可以在 ARMv7 设备上运行和运行,并且使用 Mono 进行构建,所以我认为它只是以某种方式被排除在 IL2CPP 构建之外。

总之,Mono 在其构建中包含 libARWrapper.so 库,但是当我为完全相同的项目切换到 IL2CPP 时,该库未包含在内,因此无法链接。 有谁知道为什么会这样?谢谢!

解决方法

插件中的代码tries to P/Invoke into these APIs by declaring that they're in the same binary as your C# code

    [DllImport("__Internal")]
    public static extern void arwRegisterLogCallback(PluginFunctions.LogCallback callback);

    [DllImport("__Internal")]
    public static extern void arwSetLogLevel(int logLevel);
    
    [DllImport("__Internal")]
    [return: MarshalAsAttribute(UnmanagedType.I1)]
    public static extern bool arwInitialiseAR();

"__Internal" 是一个特殊的 DLL 名称,它告诉 IL2CPP 直接向这些 API 发出调用,并相信链接器能够解析它们。但是,这些 API 实际上存在于 libARWrapper.so 中(而不是 Unity 项目中松散的 .cpp 文件),因此链接器无法找到它们。将 [DllImport("__Internal")] 的所有实例更改为 [DllImport("libARWrapper.so")] 将解决您的问题。

,

Sunius' 答案适用于 Android,但它破坏了我的 WebGL 构建,抛出运行时错误“要使用 dlopen,您需要使用 Emscripten 的链接支持”。

我用条件编译修复了这个问题。例如,来自原始海报gravy

#if UNITY_WEBGL
    [DllImport("__Internal")]
    public static extern void arwSetLogLevel(int logLevel);
#else
    [DllImport("scrBrowserScripting.jslib")]
    public static extern void arwSetLogLevel(int logLevel);
#endif

希望这可以为一些人节省一些时间:-)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?