问题
项目用的Bamboo做版本自动化流程。最近给windows版本机加了一块硬盘后Unity打包apk就一直失败。 报错如下:
CommandInvokationFailure: Failed to sign APK.
D:bamboo-agent-homesdk-tools-windows-4333796build-tools28.0.3apksigner.bat sign --ks "%HOMEDRIVE%%HOMEPATH%.androiddebug.keystore" --ks-pass stdin --ks-key-alias "androiddebugkey" --key-pass stdin "C:Usersadminbamboo-agent-homexml-databuild-dirPAC-U2018-JOB1Temp/StagingAreaPackage.apk"
stderr[
Failed to load signer "signer #1"
java.io.FileNotFoundException: .androiddebug.keystore (系统找不到指定的路径。)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at com.android.apksigner.ApkSignerTool$SignerParams.loadKeyStoreFromFile(ApkSignerTool.java:832)
at com.android.apksigner.ApkSignerTool$SignerParams.loadPrivateKeyAndCertsFromKeyStore(ApkSignerTool.java:723)
at com.android.apksigner.ApkSignerTool$SignerParams.loadPrivateKeyAndCerts(ApkSignerTool.java:663)
at com.android.apksigner.ApkSignerTool$SignerParams.access$500(ApkSignerTool.java:615)
at com.android.apksigner.ApkSignerTool.sign(ApkSignerTool.java:269)
at com.android.apksigner.ApkSignerTool.main(ApkSignerTool.java:89)
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
Keystore password for signer #1:
]
exit code: 2
at UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) [0x00031] in <62f761e6ab1445a38cdcb4ac36512695>:0
at UnityEditor.Android.Command.RunWithStdin (System.Diagnostics.ProcessStartInfo psi, System.String errorMsg, System.Collections.Generic.IEnumerable`1[T] input) [0x00084] in <62f761e6ab1445a38cdcb4ac36512695>:0
at UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, System.String errorMsg, System.Collections.Generic.IEnumerable`1[T] stdin) [0x0000a] in <62f761e6ab1445a38cdcb4ac36512695>:0
at UnityEditor.Android.PostProcessor.Tasks.BuildAPK+Builder.SignPackage (UnityEditor.Android.PostProcessor.Tasks.BuildAPK+BuilderContext context, System.String abi, System.String& output) [0x0007d] in <62f761e6ab1445a38cdcb4ac36512695>:0
at UnityEditor.Android.PostProcessor.Tasks.BuildAPK+Builder.Build (UnityEditor.Android.PostProcessor.Tasks.BuildAPK+BuilderContext context, System.String abi, System.String& output) [0x00029] in <62f761e6ab1445a38cdcb4ac36512695>:0
at UnityEditor.Android.PostProcessor.Tasks.BuildAPK.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) [0x00086] in <62f761e6ab1445a38cdcb4ac36512695>:0
at UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) [0x00074] in <62f761e6ab1445a38cdcb4ac36512695>:0
UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, String, BuildTargetGroup, BuildTarget, BuildOptions, Boolean)
UnityEditor.BuildPipeline:BuildPlayerInternal(String[], String, String, BuildTargetGroup, BuildTarget, BuildOptions) (at D:unityEditorMonoBuildPipeline.bindings.cs:358)
UnityEditor.BuildPipeline:BuildPlayer(String[], String, String, BuildTargetGroup, BuildTarget, BuildOptions) (at D:unityEditorMonoBuildPipeline.bindings.cs:257)
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions) (at D:unityEditorMonoBuildPipeline.bindings.cs:240)
UnityEditor.BuildPipeline:BuildPlayer(String[], String, BuildTarget, BuildOptions) (at D:unityEditorMonoBuildPipeline.bindings.cs:235)
经过各种排查,其实就是环境变量 %HOMEDRIVE%和%HOMEPATH% 丢了,取不到正确的值。手动unity导出apk或者直接上版本机用命令行导出apk都是正常的。就是用Bamboo调用就不行了。
解决:
重启Bamboo 服务就可以了
直接重启电脑是无效的,据说就是因为重启电脑电脑后,服务自动启动时用户登录不正常,所以才获取不到用户路径等相关环境变量。必须要到服务应用中重启该服务才行。
![f52cf15207b3ba972b9451c4ec4f2991.png](https://i-blog.csdnimg.cn/blog_migrate/ba1825e27180100c37f64ecac513c76e.jpeg)