前言
哈哈,mono linker
, Xamarin
开发人员最大的敌人之一。不过不用害怕,欲先取之,必先予之。我们现在就来分析一下 Linker
吧
什么是 Linker Analyzer?
Linker Analyzer
是一个命令行工具,用于分析在 LinkAssemblies
步骤中记录的依赖关系。它将显示哪些 items
已被标记并导致链接的程序集。
The Linker Analyzer is a command line tool that analyzes dependencies which are recorded during the LinkAssemblies step. It will show you what items were marked and resulted in the linked assembly.
入门
您可以针对你的 Xamarin.Android
app 使用以下命令:
msbuild 环境变量配置参考:https://www.jianshu.com/p/88885c57bd82
这将生成一个 linker-dependencies.xml.gz
文件,解压缩之后可以提取 linker-dependencies.xml
.
The linker-dependencies.xml file
该 linker-dependencies.xml
文件是一个 xml
,里面包括所有被标记要保存在你的 App 中的 item
。您可以在编辑器中打开此文件,例如 Notepad++
The linker-dependencies.xml file is a xml that includes every item that was marked to keep in your application.
对比 linker-dependencies.xml 文件
Now one of the best tools in our toolkit is the ability to generate a linker-dependencies.xml
file with each of the linker options enabled:
- Don’t Link (Small file)
- Link SDK Assemblies (Medium file)
- Link All Assemblies (Large file)
然后我们可以使用比较工具,例如:
https://www.scootersoftware.com/download.php(Windows)
https://www.kaleidoscopeapp.com/(Mac)
在每个 linker option
之间进行比较,以查看在 assembly
中 linker
之间的区别。这对优化我们的应用程序特别有用。
分析类型
我们还可以使用 Mono
自带的 linkeranalyzer.exe
工具来 analyze types
注意: 这是要配置
PATH
环境变量的
- C:\Program Files\Mono\lib\mono\4.5 (Windows)
- /Library/Frameworks/Mono.framework/Versions/{Version}/lib/mono/4.5 (Mac)
You can then use this tool to determine why a type was marked by the linker. For example if we wanted to see why our custom application was marked by the linker, we might first start with the parent type to see dependencies:
Output:
We can then see that mayday.Droid.MaydayApplication
is our dependency as it is based on the Application
type. Let’s analyze that type now:
Output:
Linker 统计分析
您还可以获取程序集中链接内容的统计信息:
Output:
总结
This is only a surface level of how to use this tool to help diagnose linker issues in your application. This tool is extremely useful for seeing what is ultimately making your linked assemblies.
非常感谢Radek Doulik(https://github.com/radekdoulik)提供精彩的工具和文档!
Further documentation:
https://github.com/mono/mono/tree/master/mcs/tools/linker-analyzer
原文链接: https://www.jon-douglas.com/2017/09/22/linker-analyzer/
参考链接
https://stackoverflow.com/questions/29124520/xamarin-linker-removing-reference-to-third-party-dllhttps://docs.microsoft.com/en-us/xamarin/android/deploy-test/linkerhttps://xamarinhelp.com/xamarin-linker/