【问题标题】:Running ibtool has part of iOS build breaks build unless ran clean first运行 ibtool 有一部分 iOS 构建会中断构建,除非先运行干净
【发布时间】:2013-10-01 11:06:22
【问题描述】:

添加了一个运行的构建脚本步骤

ibtool ./Mobile/Base.lproj/MainStoryboard_iPad.storyboard --generate-strings-file ./Mobile/Base.lproj/MainStoryboard_iPad.strings

构建失败

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.ibtool.errors</key>
<array>
    <dict>
        <key>description</key>
        <string>Interface Builder could not open the document "MainStoryboard_iPad.storyboard" because it does not exist.</string>
    </dict>
</array>
</dict>
</plist>
Command /bin/sh failed with exit code 1

项目先清理后构建,第一次就成功了。

我试图在示例项目中复制它,但无法复制它。我们的实际项目要复杂得多……有 6 种语言,项目有两个目标(一个用于企业构建,一个用于商店构建)。许多类和两个大型故事板。

有没有人建议尝试采取不同的方法来找出导致问题的原因以确定它是否是工具错误?

【问题讨论】:

标签: ios xcode internationalization xcode5


【解决方案1】:

ibtool 在错误的目录中运行。始终使用 ibtool 的绝对路径,而不是相对路径。

这很奇怪,绝对是一个错误;可能是 ibtool 实际上是在告诉 Xcode 的运行副本来完成这项工作。

如果您使用ibtool --output-format human-readable-text,错误消息会包含它尝试打开的实际路径,从而揭示问题。

这很难解决,因为 OSX 缺少基本工具——没有 strace,并且 dtruss 只能以 root 身份运行。

【讨论】:

    【解决方案2】:

    我也收到类似“Interface Builder 无法打开文档“YourStupid.xib”的消息,因为它不存在。”

    对我有用的是设置默认 Xcode。我的系统上有两个版本的 Xcode,虽然我从不使用旧版本,但它仍然存在。我从下载页面而不是通过 App Store 安装了我的 Xcode。我在这里谈论的是 Xcode 5.0。要设置要使用的默认 Xcode,请使用 sudo 运行以下命令。 xcode-select 需要 sudo 才能运行。

    sudo xcode-select -s /Applications/Xcode.app
    

    之后,我的 ibtool 再次工作。对我来说,它可以在没有这里提到的 sudo 解决方案的情况下工作。

    我感觉在安装文档集后出现了这个问题。在阅读了这里的一些帖子并思考了哪些变化之后,我想到了我过去在第一次安装 Jenkins、Xcode 和权限(sudo 命令)时遇到的问题,然后又回到了这个命令。

    到目前为止,这对我有用,从那以后我没有发现任何问题。您的里程可能会有所不同。

    【讨论】:

      【解决方案3】:

      我知道这是一个老问题,但我的情节提要遇到了类似的问题,并更新了我在 Internet 上找到的一个脚本,该脚本在调用 ibtool 时使用情节提要的完整路径。您将在下面找到脚本

      #!/bin/sh
      # Update storyboard string files
      #
      # by 2013 André Pinto andredsp@gmail.com
      # based on http://forums.macrumors.com/showthread.php?t=1467446
      
      storyboardExt=".storyboard"
      stringsExt=".strings"
      newStringsExt=".strings.new"
      oldStringsExt=".strings.old"
      localeDirExt=".lproj"
      baselprojName="Base.lproj"
      
      # Find Base internationalization folders
      find . -name "$baselprojName" | while read baselprojPath
      do
          # Get Base project dir
          baselprojDir=$(dirname "$baselprojPath")
      
          # Find storyboard file full path inside base project folder
          find "$baselprojPath" -name "*$storyboardExt" | while read storyboardPath
          do
              # Get Base strings file full path
              baseStringsPath=$(echo "$storyboardPath" | sed "s/$storyboardExt/$stringsExt/")
      
              # Get storyboard file name and folder
              storyboardFile=$(basename "$storyboardPath")
              storyboardDir=$(dirname "$storyboardPath")
      
              #Get the full path of the storyboard and the temporary string files. This is the fix for ibtool error
              storyboardFullPath=$(echo $(echo `pwd`)$(echo "$storyboardPath" | cut  -c2-))
              newBaseStringsFullPath=$(echo `pwd`"/Main.strings.new")
      
              echo "Full path of the storyboard $storyboardFullPath"
              echo "Full path of the temporary string files $newBaseStringsFullPath"
      
              # Get New Base strings file full path and strings file name
              stringsFile=$(basename "$baseStringsPath")
      
              # Create strings file only when storyboard file newer
              newer=$(find "$storyboardPath" -prune -newer "$baseStringsPath")
              [ -f "$baseStringsPath" -a -z "$newer" ] && {
                  echo "$storyboardFile file not modified."
                  continue
              }
      
              echo "Creating default $stringsFile for $storyboardFile..."
      
              ibtool --export-strings-file "$newBaseStringsFullPath" "$storyboardFullPath"
              iconv -f UTF-16 -t UTF-8 "$newBaseStringsFullPath" > "$baseStringsPath"
              rm "$newBaseStringsFullPath"
      
              # Get all locale strings folder with same parent as Base
              ls -d "$baselprojDir/"*"$localeDirExt" | while read localeStringsDir
              do
                  # Skip Base strings folder
                  [ "$localeStringsDir" = "$storyboardDir" ] && continue
      
                  localeDir=$(basename "$localeStringsDir")
                  localeStringsPath="$localeStringsDir/$stringsFile"
      
                  # Just copy base strings file on first time
                  if [ ! -e "$localeStringsPath" ]; then
                      echo "Copying default $stringsFile for $localeDir..."
                      cp "$baseStringsPath" "$localeStringsPath"
                  else
                      echo "Merging $stringsFile changes for $localeDir..."
                      oldLocaleStringsPath=$(echo "$localeStringsPath" | sed "s/$stringsExt/$oldStringsExt/")
                      cp "$localeStringsPath" "$oldLocaleStringsPath"
      
                      # Merge baseStringsPath to localeStringsPath
                      awk '
      NR == FNR && /^\/\*/ {
          x=$0
          getline
          a[x]=$0
          next
      }
      /^\/\*/ {
          x=$0
          print
          getline
          $0=a[x]?a[x]:$0
          printf $0"\n\n"
      }'  "$oldLocaleStringsPath" "$baseStringsPath" > "$localeStringsPath"
      
                      rm "$oldLocaleStringsPath"
                  fi
              done
          done
      done
      

      【讨论】:

      【解决方案4】:

      我在使用带有常规 xib 文件的 Xcode 5 时遇到了同样的问题。 ibtools 随机工作。使用 sudo 终于成功了。

      这是一个例子:

      $ibtool --generate-strings-file en.lproj/MyVC.strings en.lproj/MyVC.xib
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"     
      "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
      <key>com.apple.ibtool.errors</key>
      <array>
          <dict>
              <key>description</key>
              <string>Interface Builder could not open the document "MyVC.xib" because it does not exist.</string>
          </dict>
      </array>
      </dict>
      </plist>
      

      使用 sudo 每次都有效,尽管它有时会抱怨“用户域会不稳定”

      $sudo ibtool --generate-strings-file en.lproj/MyVC.strings en.lproj/MyVC.xib
      2013-10-01 10:04:35.943 Interface Builder Cocoa Touch Tool[1717:303] CFPreferences: user       
      home directory at file:///var/root/Library/Application%20Support/iPhone%20Simulator/User/ is unavailable. User domains will be volatile.
      $
      

      【讨论】:

      • 天哪,我有一个python脚本:(
      • 作为临时解决方案工作。应该有更好的方法,因为我在我的工作机器上没有 sudo 权限。
      • 这个修复确实有效,也解决了我的问题。我不敢相信。谢谢!
      猜你喜欢
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 2016-02-09
      • 1970-01-01
      • 2017-03-17
      相关资源
      最近更新 更多