• python执行unity打包


    由于打包机并没有图形界面,在满屏的日志里面找错误又比较繁琐。所以需要捕获日志的错误在最后显示
    使用管道执行unityeditor命名空间下的打包方法。指定-logFile参数日志输出到stdout
    返回非0值给shell捕获返回

    import os
    import subprocess
    
    def cmd(command):
        p= subprocess.Popen(command,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        errLines=[]
        while p.poll() is None:
                line = p.stdout.readline()
                line = line.strip().decode("utf-8")
                print(line)
                if ": error" in line or "Exception:" in line:
                    errLines.append(line)
                    
        if p.returncode == 0:
            print('success')
        else:
            print('fail')
            for line in errLines:
                print(line)
            exit(1)
    
    def main():
        unityPath = "F:/unity/2019.4.28f1c1/Editor/Unity.exe"
        projectPath = os.getcwd()
        method = "BuildTool.BuildSetting"
        cmd("{} -quit -batchmode -projectPath {} -executeMethod {} -logFile -nographics"
            .format(unityPath,projectPath,method))
    
    if __name__ == "__main__":
        main()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    最后把错误打印出来。方便查找原因

    Scan: 30.291ms
    OnSourceAssetsModified: 0.000ms
    UnregisterDeletedAssets: 0.000ms
    InitializeImportedAssetsSnapshot: 7.527ms
    GetAllGuidsForCategorization: 0.000ms
    CategorizeAssets: 0.000ms
    ImportAndPostprocessOutOfDateAssets: 0.000ms (0.000ms without children)
    ImportManagerImport: 0.000ms (0.000ms without children)
    ImportInProcess: 0.000ms
    ImportOutOfProcess: 0.000ms
    UpdateCategorizedAssets: 0.000ms
    RemoteAssetCacheGetArtifact: 0.000ms (0.000ms without children)
    RemoteAssetCacheResolve: 0.000ms
    RemoteAssetCacheDownloadFile: 0.000ms
    CompileScripts: 0.000ms
    PostProcessAllAssets: 0.000ms
    ReloadImportedAssets: 0.000ms
    VerifyAssetsAreUpToDateAndCorrect: 0.000ms
    EnsureUptoDateAssetsAreRegisteredWithGuidPM: 0.000ms
    InitializingProgressBar: 0.000ms
    PostProcessAllAssetNotificationsAddChangedAssets: 0.000ms
    OnDemandSchedulerStart: 0.000ms
    RestoreLoadedAssetsState: 0.000ms
    InvokeProjectHasChanged: 0.000ms
    UpdateImportedAssetsSnapshot: 0.000ms
    ReloadSourceAssets: 0.000ms
    UnloadImportedAssets: 0.000ms
    Hotreload: 0.102ms
    FixTempGuids: 0.015ms
    VerifyGuidPMRegistrations: 0.000ms
    GatherAllCurrentPrimaryArtifactRevisions: 1.013ms
    UnloadStreamsBegin: 0.084ms
    LoadedImportedAssetsSnapshotReleaseGCHandles: 2.447ms
    GetLoadedSourceAssetsSnapshot: 2.884ms
    PersistCurrentRevisions: 0.000ms
    UnloadStreamsEnd: 0.059ms
    GenerateScriptTypeHashes: 0.000ms
    Untracked: 1.646ms
    Refresh completed in 0.162346 seconds.
    RefreshInfo: RefreshV2(NoUpdateAssetOptions)
    RefreshProfiler: Total: 162.313ms
    InvokeBeforeRefreshCallbacks: 0.001ms
    ApplyChangesToAssetFolders: 0.094ms
    WriteModifiedImportersToTextMetaFiles: 0.000ms
    CleanLegacyArtifacts: 0.000ms
    Scan: 88.633ms
    OnSourceAssetsModified: 0.000ms
    UnregisterDeletedAssets: 0.000ms
    InitializeImportedAssetsSnapshot: 5.141ms
    GetAllGuidsForCategorization: 0.382ms
    CategorizeAssets: 46.687ms
    ImportAndPostprocessOutOfDateAssets: 9.880ms (2.479ms without children)
    ImportManagerImport: 0.000ms (0.000ms without children)
    ImportInProcess: 0.000ms
    ImportOutOfProcess: 0.000ms
    UpdateCategorizedAssets: 0.000ms
    RemoteAssetCacheGetArtifact: 0.000ms (0.000ms without children)
    RemoteAssetCacheResolve: 0.000ms
    RemoteAssetCacheDownloadFile: 0.000ms
    CompileScripts: 0.000ms
    PostProcessAllAssets: 0.001ms
    ReloadImportedAssets: 0.000ms
    VerifyAssetsAreUpToDateAndCorrect: 0.000ms
    EnsureUptoDateAssetsAreRegisteredWithGuidPM: 1.376ms
    InitializingProgressBar: 0.000ms
    PostProcessAllAssetNotificationsAddChangedAssets: 0.837ms
    OnDemandSchedulerStart: 0.885ms
    RestoreLoadedAssetsState: 4.302ms
    InvokeProjectHasChanged: 0.000ms
    UpdateImportedAssetsSnapshot: 0.000ms
    ReloadSourceAssets: 2.422ms
    UnloadImportedAssets: 0.354ms
    Hotreload: 0.114ms
    FixTempGuids: 0.013ms
    VerifyGuidPMRegistrations: 0.000ms
    GatherAllCurrentPrimaryArtifactRevisions: 0.737ms
    UnloadStreamsBegin: 0.096ms
    LoadedImportedAssetsSnapshotReleaseGCHandles: 2.457ms
    GetLoadedSourceAssetsSnapshot: 6.864ms
    PersistCurrentRevisions: 0.000ms
    UnloadStreamsEnd: 0.051ms
    GenerateScriptTypeHashes: 0.000ms
    Untracked: -1.613ms
    Initializing Unity extensions:
    'F:/unity/2019.4.28f1c1/Editor/Data/UnityExtensions/Unity/UnityVR/Editor/UnityEditor.VR.dll'  GUID: 4ba2329b63d54f0187bcaa12486b1b0f
    Unloading 78 Unused Serialized files (Serialized files now loaded: 0)
    System memory in use before: 56.5 MB.
    System memory in use after: 55.8 MB.
    
    Unloading 154 unused Assets to reduce memory usage. Loaded Objects now: 2517.
    Total: 10.654000 ms (FindLiveObjects: 1.483200 ms CreateObjectMapping: 0.524500 ms MarkObjects: 7.094800 ms  DeleteObjects: 1.549400 ms)
    
    Refreshing native plugins compatible for Editor in 13.10 ms, found 0 plugins.
    Scripts have compiler errors.
    (Filename: E:\unity\Runtime/Utilities/Argv.cpp Line: 376)
    
    
    Aborting batchmode due to failure:
    Scripts have compiler errors.
    
    
    Aborting batchmode due to failure:
    Scripts have compiler errors.
    
    Exiting without the bug reporter. Application will terminate with return code 1
    fail
    Assets\Scripts\Core\Updater.cs(127,44): error CS0104: 'Tools' is an ambiguous reference between 'JEngine.Core.Tools' and 'UnityEditor.Tools'
    Assets\Scripts\Core\Updater.cs(128,76): error CS0104: 'Tools' is an ambiguous reference between 'JEngine.Core.Tools' and 'UnityEditor.Tools'
    Assets\Scripts\Core\Updater.cs(138,38): error CS0104: 'Tools' is an ambiguous reference between 'JEngine.Core.Tools' and 'UnityEditor.Tools'
    Assets\Scripts\Core\Updater.cs(127,44): error CS0104: 'Tools' is an ambiguous reference between 'JEngine.Core.Tools' and 'UnityEditor.Tools'
    Assets\Scripts\Core\Updater.cs(128,76): error CS0104: 'Tools' is an ambiguous reference between 'JEngine.Core.Tools' and 'UnityEditor.Tools'
    Assets\Scripts\Core\Updater.cs(138,38): error CS0104: 'Tools' is an ambiguous reference between 'JEngine.Core.Tools' and 'UnityEditor.Tools'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
  • 相关阅读:
    js中的instance,isPrototype和getPrototypeOf的使用,来判断类的关系
    leetcode系列(双语)003——GO无重复字符的最长子串
    MyBatis-动态 SQL 语句
    Redis实现微博好友功能微服务(关注,取关,共同关注)
    Git 常用命令
    2023-11-20 LeetCode每日一题(最大子数组和)
    二阶低通滤波器(二阶巴特沃斯滤波器)
    Windows应急响应排查
    入职面经!!!
    锂电池升压3V,3.3V,3.7V升压5V,9V,12V大小电流方案合集
  • 原文地址:https://blog.csdn.net/qq_17813937/article/details/132928325