VS中的发布模式和调试模式

Dan*_*ian 1 c# java android visual-studio xamarin

我目前正在开发一个 Android 应用程序,并且对 VS 进行了一些修改。

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

在我的研究过程中,我遇到了问题1、23,谈论了两者之间的差异

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

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

  1. 那些调试符号是什么?
  2. obj/Debug 或 obj/Release 中的“81”文件夹是什么?
  3. 我还注意到,有时,当从调试切换到发布时,找不到某些 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   
Run Code Online (Sandbox Code Playgroud)
  1. 这些警告真的是我在发布应用程序时需要担心的吗?它们会导致更多错误吗?

我已经尝试过:

  1. 删除这些文件。

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

eug*_*man 5

我尝试向您提供简要概述并添加一些参考资料。你不会过来阅读一些书籍或网页。

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

实际例子

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

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

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

对于您的问题:

1. 为什么debug模式比release模式运行慢?

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

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

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

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

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

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

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

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

我不知道你为什么关心 obj 文件夹,但 81 包含在构建过​​程中使用的 8.1 版本的 android 内容

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

我还在较旧的 Visual Studio 版本中观察到了这种行为。目前我使用 VS 15.9.4 和 Xamarin 4.3.12.77,通常效果很好。源的问题可能是资源 ID 是在构建过程中生成的。当您切换到发布配置时,还必须生成这些符号以供发布,也许 VS 会把事情搞砸。

7. 在发布应用程序时,这些警告真的是我需要担心的吗?它们会导致更多错误吗?

不用担心这个!丢失的 Pdb 文件不会给您带来任何麻烦,因为它们没有捆绑到 apk 中。

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