简体   繁体   English

应用程序在发布版本中崩溃,但在调试中没有崩溃

[英]App crashes in Release build but not in debug

As I said in the title, I am writing an app for iPhone which runs perfectly in debug mode but when I build it as release and install it via TestFlight, it crashes. 正如我在标题中所说,我正在为iPhone编写一个应用程序,它在调试模式下运行完美,但当我将其构建为发布并通过TestFlight安装时,它会崩溃。 Due to the crash log it might have to do something with this lines: 由于崩溃日志,它可能必须使用以下行:

let path = NSBundle.mainBundle().pathForResource("PrinterList", ofType: "plist")
if path != nil {
    let printerDic = NSDictionary(contentsOfFile: path!)
    let printerList = NSArray(array: printerDic.allKeys)
    printerNames = printerList as [String]
}

I am using an framework from Brother to print without AirPrint, but I think thats not the problem because the app crashes before doing something with the framework. 我使用Brother的框架在没有AirPrint的情况下进行打印,但我认为这不是问题,因为应用程序在使用框架之前崩溃了。 It crashes only in this ViewController where I execute these lines. 它只在我执行这些行的ViewController中崩溃。 I need the framework only in this ViewController as well. 我也只需要在这个ViewController中使用框架。

There are many reasons that an app might crash in release mode but not in debug mode (eg memory allocation differences showing up a bug that actually exists in both builds.) They can take a lot of work to track down, even with a non-beta compiler/language. 应用程序可能在发布模式下崩溃但在调试模式下不会崩溃的原因有很多(例如,内存分配差异显示两个版本中实际存在的错误。)即使使用非错误,它们也可能需要大量工作才能跟踪beta编译器/语言。

You say that the problem goes away if you do as I suggested and build for release with optimisations turned off. 你说如果你像我建议的那样做,并且在关闭优化的情况下构建发布版本,问题就会消失。 Given that the Swift compiler is still in beta and definitely still has the occasional problem—I've seen the compiler simply crash when building optimised builds—this may actually be an optimiser bug. 鉴于Swift编译器仍然处于测试阶段并且肯定仍然存在偶然的问题 - 我已经看到编译器在构建优化版本时会崩溃 - 这实际上可能是一个优化器错误。

For now, therefore, I'd defer looking into it. 因此,现在,我推迟调查。 Release without optimisations until we get a full release version of the compiler. 在我们获得编译器的完整发行版之前,不进行优化发布。 Then, turn optimisations back on and see if you still have the problem. 然后,重新启用优化并查看是否仍有问题。 If you do, that's the time to start spending your energy trying to figure out if it's a compiler bug or a bug in your own code. 如果你这样做, 那就是开始消耗能量的时候,试图找出它是编译器错误还是你自己代码中的错误。

I've had the same problem. 我遇到了同样的问题。 I finally fixed it by turning on whole module optimization . 我最后通过打开whole module optimization修复它。 Combined with correct implementations of access control this should fix your crash. 结合正确的访问控制实现,这应该可以解决您的崩溃问题。

Whole module optimization according to Apple: 根据Apple的整个模块优化:

Use Whole Module Optimization to infer final on internal declarations. 使用整个模块优化来推断内部声明的最终结果。 Declarations with internal access (the default if nothing is declared) are only visible within the module where they are declared. 具有内部访问权限的声明(如果未声明任何内容,则为默认声明)仅在声明它们的模块中可见。 Because Swift normally compiles the files that make up a module separately, the compiler cannot ascertain whether or not an internal declaration is overridden in a different file. 因为Swift通常单独编译组成模块的文件,所以编译器无法确定是否在不同的文件中覆盖了内部声明。 However, if Whole Module Optimization is enabled, all of the module is compiled together at the same time. 但是,如果启用了整个模块优化,则所有模块将同时编译在一起。 This allows the compiler to make inferences about the entire module together and infer final on declarations with internal if there are no visible overrides. 这允许编译器一起推断整个模块,如果没有可见的覆盖,则使用internal推断最终的声明。

You can enable this in your project settings: 您可以在项目设置中启用它:

整个模块优化

But be aware this option optimizes all of the files in a target together and enables better performance at the cost of increased compile time. 但要注意,此选项可以优化目标中的所有文件,并以增加编译时间为代价实现更好的性能。

To catch the crash test the with the Optimization Level set to Fastest, Smallest [-Os] in Debug mode to more closely simulate the code that will be generated & running on the user's device. 要捕获崩溃测试,优化级别设置为最快,调试模式下最小的[-Os],以更接近地模拟将在用户设备上生成和运行的代码。

You can set it in build settings, under Swift Compiler/Code Generation 您可以在Swift编译器/代码生成下的构建设置中进行设置

Apple also describes a known issue . Apple还描述了一个已知问题 I describe it briefly in case someone is look for answer and the previous solution doesn't work. 我简要描述一下,以防有人寻找答案而前一个解决方案不起作用。

Check your crashlog for errors like 检查崩溃日志中是否有错误

Dyld Error Message:
  Library not loaded: @rpath/libswiftCore.dylib

or 要么

[....] [deny-mmap] mapped file has no team identifier and is not a platform binary:
/private/var/mobile/Containers/Bundle/Application/5D8FB2F7-1083-4564-94B2-0CB7DC75C9D1/YourAppNameHere.app/Frameworks/libswiftCore.dylib

and follow apple guidance if you have similar crash output like the one above. 如果您有类似上面的碰撞输出,请按照Apple 指导进行操作

PS: You could check the log easily even under Window ->Device in XCode. PS:即使在XCode中的Window - > Device下,您也可以轻松查看日志。 click to the device and click view device logs. 单击设备,单击“查看设备日志”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 performSelector:withObject:afterDelay使应用程序在发行时崩溃,但未调试 - performSelector:withObject:afterDelay crashes app in release but not debug iOS App在存档版本中崩溃,但不发布/运行 - iOS App crashes in Archive Build but not Release/Run 针对“应用商店版本”和“开发/调试版本”的设备特定的构建设置? - Device specific build settings for “app store release” and “development/debug release”? ios应用程序可以在调试模式下完美运行,但在发行时崩溃 - ios app runs perfectly in debug mode but crashes in release App Release Version崩溃Debug Version有效,不知道为什么 - App Release Version crashes Debug Version works, no idea why React Native 应用程序在发布模式下崩溃,但在调试模式下工作正常 - React Native app crashes in release mode but works fine in debug mode 使用预处理器宏来确定应用程序构建是用于调试还是发布 - Using preprocessor macro to decide if app build is for debug or release iOS-应用在“发行版”中崩溃,但不在“调试”模式下崩溃。 [__NFCString count]:无法识别的选择器已发送到实例xxx - iOS - App crashes in Release but not in Debug mode. [__NFCString count]: unrecognized selector sent to instance xxx 在iOS应用的发行版中向下转换“ folderID = folder.folderID as Int”会崩溃,但在调试版本中不会崩溃。 使用有危险吗? - Downcasting “folderID = folder.folderID as Int” crashes in release version of iOS app, but not in the debug version. Is it dangerous to use? 我的 react-native 应用程序在调试模式下启动正常,但在构建发布时,启动时崩溃 - My react-native app launches fine in Debug mode, but when built Release, crashes on launch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM