美文网首页
Xcode打包失败,因Python3执行脚本出错

Xcode打包失败,因Python3执行脚本出错

作者: 满庭花醉三千客 | 来源:发表于2019-08-19 11:11 被阅读0次

    今天使用Xcode打包失败了。。

    屏幕快照 2019-08-16 下午5.02.35.png

    点击“Show Logs”查看日志得到以下错误信息:

    
    {
    
                code = 679;
    
                description = "ipatool failed with an exception: #<CmdSpec::NonZeroExcitException: /usr/bin/python exited with pid 54505 exit 1\nStdout:\n\nStderr:\n    Traceback (most recent call last):\n      File \"<string>\", line 1, in <module>\n    AttributeError: 'str' object has no attribute 'decode'\n>\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:227:in `run'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:210:in `run'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:139:in `unicode_equal?'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `block in MakeFileSystemNode'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `each'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `detect'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `MakeFileSystemNode'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1461:in `initialize'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2355:in `new'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2355:in `ProcessIPA'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3009:in `<main>'";
    
                info =             {
    
                };
    
                level = ERROR;
    
                type = exception;
    
            }
    

    可以看出来,错误信息是在ipatool脚本:

    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool这个python文件中

    我们找到这个文件:


    屏幕快照 2019-08-16 下午5.12.04.png

    然后找到第227行:

    屏幕快照 2019-08-16 下午5.13.04.png

    确实是NonZeroExcitException错误,接下来找到210行,是调用run这个方法,没什么问题。继续找第139行,137-140行内容为:

    
    # We still support Ruby 2.0, so we need a workaround for unicode equivalence
    
      def unicode_equal?(other)
    
        return CmdSpec.new(locate_tool("python"), ["-c", "import sys; import unicodedata; print(unicodedata.normalize('NFC', sys.argv[1].decode('utf-8')) == unicodedata.normalize('NFC', sys.argv[2].decode('utf-8')))", self, other]).run(0, false, true).strip == "True"
    
      end
    

    我们看到了一个decode函数,这个和报错内容:

    AttributeError: 'str' object has no attribute 'decode'

    匹配上了。我们修改一下这个Python文件,将decode改为encode之后保存,再运行,继续报错。。

    {
    
                code = 679;
    
                description = "ipatool failed with an exception: #<CmdSpec::NonZeroExcitException: /usr/bin/python exited with pid 55146 exit 1\nStdout:\n\nStderr:\n    Traceback (most recent call last):\n      File \"<string>\", line 1, in <module>\n    TypeError: normalize() argument 2 must be str, not bytes\n>\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:227:in `run'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:210:in `run'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:139:in `unicode_equal?'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `block in MakeFileSystemNode'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `each'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `detect'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1758:in `MakeFileSystemNode'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1461:in `initialize'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2355:in `new'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2355:in `ProcessIPA'\n    /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3009:in `<main>'";
    
                info =             {
    
                };
    
                level = ERROR;
    
                type = exception;
    
            }
    

    这次的报错是:

    TypeError: normalize() argument 2 must be str, not bytes
    

    报错不一样了,是python字符串的问题,将137-140行内容改为:

    
    # We still support Ruby 2.0, so we need a workaround for unicode equivalence
    
      def unicode_equal?(other)
    
        return CmdSpec.new(locate_tool("python"), ["-c", "import sys; import unicodedata; print(unicodedata.normalize('NFC', sys.argv[1].encode('unicode_escape').decode('utf-8')) == unicodedata.normalize('NFC', sys.argv[2].encode('unicode_escape').decode('utf-8')))", self, other]).run(0, false, true).strip == "True"
    
      end
    

    请注意核心改动的地方是:

    print(unicodedata.normalize('NFC', sys.argv[1].encode('unicode_escape').decode('utf-8')) == unicodedata.normalize('NFC', sys.argv[2].encode('unicode_escape').decode('utf-8'))
    

    Python2.x版本中字符串默认ASCII编码,有decode方法,decode成Unicode编码;Python3.x版本中默认是Unicode编码,我是先把他转成ASCII编码,然后解码的。

    效果:

    屏幕快照 2019-08-19 上午10.57.27.png

    可以继续正常打包了~
    加油~

    相关文章

      网友评论

          本文标题:Xcode打包失败,因Python3执行脚本出错

          本文链接:https://www.haomeiwen.com/subject/zsqssctx.html