genstrings 工具抛出异常,解析 XCode 项目时中止
我一直在使用 genstrings 构建字符串文件来国际化我的 iPhone 应用程序。但是,我最近所做的一些更改导致 genstrings 工具开始抛出如下错误:
s1075-88:Directory jason$ genstrings -o en.lproj *.m
2011-02-26 16:42:26.941 genstrings[17962:903] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString characterAtIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff82a267b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff85c640f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff82a265d7 +[NSException raise:format:arguments:] + 103
3 CoreFoundation 0x00007fff82a26564 +[NSException raise:format:] + 148
4 Foundation 0x00007fff841a65e1 -[NSCFString characterAtIndex:] + 97
5 genstrings 0x0000000100001b9d 0x0 + 4294974365
6 genstrings 0x0000000100003080 0x0 + 4294979712
7 genstrings 0x0000000100003ee6 0x0 + 4294983398
8 genstrings 0x0000000100000d20 0x0 + 4294970656
)
可能导致此问题的原因是什么,以及如何在不手动更改所有内容的情况下找到导致此问题的项目部分?
I've been using genstrings
to build strings files to internationalize my iPhone app. However, some changes I made recently have caused the genstrings
tool to start throwing errors like this:
s1075-88:Directory jason$ genstrings -o en.lproj *.m
2011-02-26 16:42:26.941 genstrings[17962:903] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString characterAtIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff82a267b4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff85c640f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff82a265d7 +[NSException raise:format:arguments:] + 103
3 CoreFoundation 0x00007fff82a26564 +[NSException raise:format:] + 148
4 Foundation 0x00007fff841a65e1 -[NSCFString characterAtIndex:] + 97
5 genstrings 0x0000000100001b9d 0x0 + 4294974365
6 genstrings 0x0000000100003080 0x0 + 4294979712
7 genstrings 0x0000000100003ee6 0x0 + 4294983398
8 genstrings 0x0000000100000d20 0x0 + 4294970656
)
What could be causing this, and how can I find the part of my project which is causing it without manually changing everything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这里没有简单的技巧。
将所有 .m 文件复制到单独的文件夹中,然后进行二分搜索。
对一半文件运行 genstrings 并查看问题是否存在。隔离哪一半文件有问题,然后再做一次...
这是 genstrings 内部的一个错误,所以你对此无能为力。
No easy tricks here.
copy all your .m files to a separate folder then do a binary search.
run genstrings on half the files and see if the problem is there or not. isolate which half of the files have the problem and do it again...
It's a bug inside genstrings, so not much you can do about it.
您可以使用
head
来限制genstrings
处理的文件数量。如果这是本地化所有文件的命令:那么使用
head
时的情况如下:只需增加 head 旁边的数字并一次又一次运行该命令,直到崩溃。在运行之间,您可以删除临时
GenStrinsTest
文件夹中的文件。当它崩溃时,减少数字,直到现在准确地崩溃,然后运行,并且将在控制台上写入的最后一个文件将是“错误”的文件。
You could limit the numbers of file processed by
genstrings
by usinghead
. If this is your command to localize all files:Then this is how it looks like when using
head
:Just increase the number next to head and run the command again and again, until it crashes. Between runs, you can delete the files in the temporary
GenStrinsTest
folder. When it crashes, decrease the number until you now exactly where it crashes and then runand the last file that will be written on the console will be the "wrong" one.
如果它对其他人有帮助,我在评论中包含 NSLocalizedString 时会发生崩溃。我猜它找到了它并且没有参数并且崩溃了
In case it helps anyone else, I got this crash when having an NSLocalizedString in a comment. I guess it found it and it didn't have parameters and crashes
我遇到了这个问题。就我而言,genstrings 正在扫描 git merge 留下的
.m.orig
文件。删除 *.m.orig 文件可以解决问题,因为它们肯定包含格式错误的本地化字符串。I ran into this issue. In my case, genstrings was scanning
<filename>.m.orig
files left over from a git merge. Deleting the*.m.orig
files fixed things, as they must have contained malformed localized strings.对我来说,它由于 NSLocalizedString 调用中的注释而崩溃。
例如:
导致 genstrings 崩溃,但这很好:
For me it crashed due to a comment inside an NSLocalizedString call.
For example:
causes crashes genstrings, but this is fine:
Swift 4
语法似乎也会使其崩溃。
having Swift 4
syntax seems to make it crash too.
这是当
genstrings
找不到宏调用的结尾时生成的错误。请注意,
genstrings
实用程序无法处理跨多行的调用(无论内部是否有注释)。所以这可行:
但这不行
This is the error that is generated when
genstrings
can't find the end of the macro call.Note that the
genstrings
utility can't handle calls that span multiple lines (regardless of whether there is a comment inside or not).So this works:
but this doesn't