首页 > 解决方案 > VS 中的发布模式和调试模式

问题描述

我目前正在开发一个 Android 应用程序,并且我对 VS 有点搞砸了。

我想知道,这两种模式之间的真正区别是什么?我做了一些研究,但我并没有完全了解每种模式的真正差异和优势,以及何时使用特定模式。

在我的研究过程中,我遇到了这些问题123,讨论了两者之间的差异。

  1. 为什么调试模式比发布模式运行慢?
  2. 将应用程序发布到 Google Play 时,我应该使用哪种模式,为什么?
  3. 我可以创建自己的模式吗?

我的应用程序似乎在调试模式下构建良好,但在发布模式下,我收到很多关于“未找到调试符号文件”的警告。

  1. 那些调试符号是什么?
  2. obj/Debug 或 obj/Release 中的“81”文件夹是什么?
  3. 我还注意到,有时,当从 Debug 切换到 Release 时,找不到一些 Resource.Id,我需要为布局重新创建 axml 文件并清理 sln。我该如何预防?

据我了解,调试模式使用了一些发布模式不需要运行的文件,我假设丢失的文件是那些“调试符号”?也许这是 Xamarin 或 VS 的问题?这些是我得到的警告:

Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.v7.AppCompat.dll but no debug symbols file was found.          0   
Warning     Directory obj\Release\81\android/assets contains Java.Interop.dll but no debug symbols file was found.          0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Arch.Core.Common.dll but no debug symbols file was found.          0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Arch.Lifecycle.Common.dll but no debug symbols file was found.         0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Arch.Lifecycle.Runtime.dll but no debug symbols file was found.            0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Animated.Vector.Drawable.dll but no debug symbols file was found.          0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Annotations.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Compat.dll but no debug symbols file was found.            0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Core.UI.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Core.Utils.dll but no debug symbols file was found.            0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Design.dll but no debug symbols file was found.            0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Fragment.dll but no debug symbols file was found.          0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Media.Compat.dll but no debug symbols file was found.          0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Transition.dll but no debug symbols file was found.            0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.v4.dll but no debug symbols file was found.            0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.v7.RecyclerView.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.Android.Support.Vector.Drawable.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Base.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Basement.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Maps.dll but no debug symbols file was found.           0   
Warning     Directory obj\Release\81\android/assets contains Xamarin.GooglePlayServices.Tasks.dll but no debug symbols file was found.          0   
  1. 这些警告真的是我在发布应用程序时需要担心的事情吗?它们会导致任何进一步的错误吗?

我已经尝试过:

  1. 删除那些文件。

  2. 清理解决方案和整个项目。

标签: javac#androidvisual-studioxamarin

解决方案


我试着给你一个简短的概述并添加一些参考资料。你不会过来阅读一些书籍或网页。

配置只是您用于构建的一组特定设置的标签。

实际例子

调试:供开发人员开发具有许多功能的应用程序,从而提高开发速度,例如启用完整的日志记录和调试 DevelopmentRelease:供测试团队使用。禁用调试、启用优化、完整日志记录、使用广泛的崩溃报告、使用测试基础设施(例如测试服务器) 您还可以使用不同的清单,以便您拥有不同的包名称并可以并行安装应用程序。发布:将部署到 Playstore,选择性能和稳定性 禁用调试、减少日志记录、优化代码、使用生产基础架构(例如服务器)

但是,为特定配置设置什么设置取决于您。默认情况下,发布配置将优化代码以更快地运行。此外,默认情况下,Debug 配置具有完整的 Debug 调试信息和仅用于 Release 的 pdb。但是您将无法在仅使用 pdb 的发布配置中附加调试器。

pdb 文件用于将生成的代码映射到源代码。 PDB 文件:每个开发人员都必须知道的内容

对于您的问题:

1. 为什么调试模式比发布模式运行慢?

因为已经完成了一些优化(优化代码标志)=> 更改您的代码以更快地运行。你可能不会有这种感觉。当不需要调试时还有其他性能优势,例如不需要断点解析等等。

2. 将应用程序发布到 Google Play 时,我应该使用哪种模式,为什么?

始终采用 Release 模式,因为此版本通常运行得更快、更稳定。您可能已在调试配置中设置使用共享运行时:这会将单声道运行时作为单独的应用程序部署到设备上,以便调试模式下的部署更快 => 只需部署代码中的更改。但是,当您将调试版本上传到 playstore 时,应用程序将无法运行,因为缺少共享运行时应用程序。如果您使用 Proguard 进行代码混淆,这通常也是一个仅在发布模式下启用的功能。 Proguard 主页

如果您有自动构建管道,您通常不必在本地计算机上发布构建,因为这是由构建服务器完成的。

3. 我可以创建自己的模式吗? 是的,正如我已经提到的。按配置旁边的箭头并打开配置管理器。在配置管理器中按下拉活动配置并选择新建。您还可以复制已经存在的配置。=> 总是在 *.csproj 文件中查看配置包含的内容。Visual Studio 并不总是能够复制所有配置条目。

4. 那些调试符号是什么?

您可以忽略这些警告,您不需要不属于您的代码的 pdb 文件。

5、obj/Debug或obj/Release中的“81”文件夹是什么?

我不知道你为什么关心 obj 文件夹,但 81 包含构建期间使用的 8.1 版的 android 内容

6. 我还注意到,有时从Debug切换到Release时,找不到一些Resource.Id,我需要为布局重新创建axml文件并清理sln。我该如何预防?

我还在旧的 Visual Studio 版本中观察到了这种行为。目前我将 VS 15.9.4 与 Xamarin 4.3.12.77 一起使用,这通常可以正常工作。源的问题可能是在构建过程中生成了 Resource id。当您切换到发布配置时,还必须为发布生成这些符号,并且可能 VS 会搞砸。

7. 这些警告真的是我在发布应用程序时需要担心的吗?它们会导致任何进一步的错误吗?

不用担心这个!缺少 Pdb 文件不会给您带来任何麻烦,因为它们没有绑定到 apk。

在您将您的 apk 上传到 playstore 之前,我建议您阅读以下 Android 指南 发布您的应用指南


推荐阅读