genstrings 工具抛出异常,解析 XCode 项目时中止

发布于 2024-10-19 09:39:16 字数 1251 浏览 4 评论 0原文

我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

黑白记忆 2024-10-26 09:39:16

这里没有简单的技巧。

将所有 .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.

止于盛夏 2024-10-26 09:39:16

您可以使用 head 来限制 genstrings 处理的文件数量。如果这是本地化所有文件的命令:

find . -name \*.m | xargs genstrings -o en.lproj

那么使用 head 时的情况如下:

find . -name \*.m | head -5 | xargs genstrings -o ~/Documents/GenStringsTest

只需增加 head 旁边的数字并一次又一次运行该命令,直到崩溃。在运行之间,您可以删除临时 GenStrinsTest 文件夹中的文件。当它崩溃时,减少数字,直到现在准确地崩溃,然后运行

find . -name \*.m | head -<minimum number of files for crash>

,并且将在控制台上写入的最后一个文件将是“错误”的文件。

You could limit the numbers of file processed by genstrings by using head. If this is your command to localize all files:

find . -name \*.m | xargs genstrings -o en.lproj

Then this is how it looks like when using head:

find . -name \*.m | head -5 | xargs genstrings -o ~/Documents/GenStringsTest

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 run

find . -name \*.m | head -<minimum number of files for crash>

and the last file that will be written on the console will be the "wrong" one.

豆芽 2024-10-26 09:39:16

如果它对其他人有帮助,我在评论中包含 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

海未深 2024-10-26 09:39:16

我遇到了这个问题。就我而言,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.

做个少女永远怀春 2024-10-26 09:39:16

对我来说,它由于 NSLocalizedString 调用中的注释而崩溃。

例如:

NSLocalizedString(@"some text" /* a comment */,  
                  @"some other text.");

导致 genstrings 崩溃,但这很好:

/* a comment */
NSLocalizedString(@"some text", @"some other text.");

For me it crashed due to a comment inside an NSLocalizedString call.

For example:

NSLocalizedString(@"some text" /* a comment */,  
                  @"some other text.");

causes crashes genstrings, but this is fine:

/* a comment */
NSLocalizedString(@"some text", @"some other text.");
青瓷清茶倾城歌 2024-10-26 09:39:16

Swift 4

"""
This is a comment
"""

语法似乎也会使其崩溃。

having Swift 4

"""
This is a comment
"""

syntax seems to make it crash too.

丶情人眼里出诗心の 2024-10-26 09:39:16

这是当 genstrings 找不到宏调用的结尾时生成的错误。

请注意,genstrings 实用程序无法处理跨多行的调用(无论内部是否有注释)。

所以这可行:

NSLocalizedString(@"Key", @"Comment")

但这不行

NSLocalizedString(@"Key",
                  @"Comment")

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:

NSLocalizedString(@"Key", @"Comment")

but this doesn't

NSLocalizedString(@"Key",
                  @"Comment")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文