java createprocess error=2_Caused by: java.io.IOException: Cannot run program "git": CreateProcess e...

本文介绍了在Android Studio中遇到的“系统找不到指定的文件”错误,并提供了详细的解决方案,包括检查Gradle脚本中的Git命令及正确配置环境变量。

Android项目更新之后,在project sync的时候遇到题目所示error,并且本地git在Android Studio中运行的完好,如 图1

0ee35b09d97c

image

... 97 more

Caused by: java.io.IOException: Cannot run program "git": CreateProcess error=2, 系统找不到指定的文件。

at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

at java.lang.Runtime.exec(Runtime.java:620)

at java.lang.Runtime.exec(Runtime.java:450)

at java.lang.Runtime.exec(Runtime.java:347)

at org.codehaus.groovy.runtime.ProcessGroovyMethods.execute(ProcessGroovyMethods.java:533)

at org.codehaus.groovy.runtime.dgm$895.invoke(Unknown Source)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)

at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)

at app_3otfkd58b7bou0rrjubs0kblm.getVersionCode(...\**app.gradle:76**)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)

at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:479)

at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:191)

at org.gradle.groovy.scripts.BasicScript$ScriptDynamicObject.tryInvokeMethod(BasicScript.java:130)

at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:78)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeOnDelegationObjects(ClosureMetaClass.java:430)

at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:369)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)

at org.codehaus.groovy.runtime.callsite.PogoMetaClassSit

打开如上的app.gradle中发现:

0ee35b09d97c

image

在gradle脚本中使用了git的命令,所以应该是在系统的环境变量 Path中配置git路径,然后重启才能解决这个问题(如图3):

0ee35b09d97c

image

最终重启解决了这个问题,通过搜索log我们在网上发现,很多人说重启电脑就好了,

也有人说跟github相关(这个应该是使用了github但是同样找不到git命令),还有人说配置git环境变量

最终我们发现了root cause并且成功的解决问题。

Started by user WUWENKE Running as SYSTEM Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\自动化测试 The recommended git tool is: NONE using credential e73878ec1dac9be8d63b76f179a9907f > git.exe rev-parse --resolve-git-dir C:\ProgramData\Jenkins\.jenkins\workspace\自动化测试\.git # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.origin.url https://gitee.com/weike1234/api_auto_test.git # timeout=10 Fetching upstream changes from https://gitee.com/weike1234/api_auto_test.git > git.exe --version # timeout=10 > git --version # 'git version 2.51.1.windows.1' using GIT_ASKPASS to set credentials > git.exe fetch --tags --force --progress -- https://gitee.com/weike1234/api_auto_test.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10 Checking out Revision a3b4e4b365e749ec43866d5d873213a3c95602ee (refs/remotes/origin/master) > git.exe config core.sparsecheckout # timeout=10 > git.exe checkout -f a3b4e4b365e749ec43866d5d873213a3c95602ee # timeout=10 Commit message: "第一次提交" > git.exe rev-list --no-walk a3b4e4b365e749ec43866d5d873213a3c95602ee # timeout=10 [自动化测试] $ sh -xe C:\WINDOWS\TEMP\jenkins178274333009868265.sh The system cannot find the file specified FATAL: command execution failed java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。 at java.base/java.lang.ProcessImpl.create(Native Method) at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:506) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:159) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126) Caused: java.io.IOException: Cannot run program "sh" (in directory "C:\ProgramData\Jenkins\.jenkins\workspace\自动化测试"): CreateProcess error=2, 系统找不到指定的文件。 at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089) at hudson.Proc$LocalProc.<init>(Proc.java:252) at hudson.Proc$LocalProc.<init>(Proc.java:221) at hudson.Launcher$LocalLauncher.launch(Launcher.java:995) at hudson.Launcher$ProcStarter.start(Launcher.java:507) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:144) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:92) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:164) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:527) at hudson.model.Run.execute(Run.java:1860) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44) at hudson.model.ResourceController.execute(ResourceController.java:101) at hudson.model.Executor.run(Executor.java:460) Build step 'Execute shell' marked build as failure Finished: FAILURE 哪里出问题了
10-26
Started by user admin Running as SYSTEM Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\ocr The recommended git tool is: NONE using credential 122 > git.exe rev-parse --resolve-git-dir C:\ProgramData\Jenkins\.jenkins\workspace\ocr\.git # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.origin.url http://lzgit.luxsan-ict.com/75600259/ai-llm-ocr.git # timeout=10 Fetching upstream changes from http://lzgit.luxsan-ict.com/75600259/ai-llm-ocr.git > git.exe --version # timeout=10 > git --version # 'git version 2.39.2.windows.1' using GIT_ASKPASS to set credentials 122 > git.exe fetch --tags --force --progress -- http://lzgit.luxsan-ict.com/75600259/ai-llm-ocr.git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git.exe rev-parse "origin/master^{commit}" # timeout=10 Checking out Revision 4a48d8ef4224d3ec55eb5af842a3915e2a4e9518 (origin/master) > git.exe config core.sparsecheckout # timeout=10 > git.exe checkout -f 4a48d8ef4224d3ec55eb5af842a3915e2a4e9518 # timeout=10 Commit message: "dockerfile" First time build. Skipping changelog. [ocr] $ /bin/bash C:\Windows\TEMP\jenkins14775837526206548501.sh The system cannot find the file specified FATAL: command execution failed java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。 at java.base/java.lang.ProcessImpl.create(Native Method) at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:494) at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:159) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110) Caused: java.io.IOException: Cannot run program "/bin/bash" (in directory "C:\ProgramData\Jenkins\.jenkins\workspace\ocr"): CreateProcess error=2, 系统找不到指定的文件。 at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143) at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073) at hudson.Proc$LocalProc.<init>(Proc.java:252) at hudson.Proc$LocalProc.<init>(Proc.java:221) at hudson.Launcher$LocalLauncher.launch(Launcher.java:995) at hudson.Launcher$ProcStarter.start(Launcher.java:507) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:144) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:92) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818) at PluginClassLoader for maven-plugin//hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.build(MavenModuleSetBuild.java:944) at PluginClassLoader for maven-plugin//hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:681) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:527) at hudson.model.Run.execute(Run.java:1860) at PluginClassLoader for maven-plugin//hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543) at hudson.model.ResourceController.execute(ResourceController.java:101) at hudson.model.Executor.run(Executor.java:454) Build step 'Execute shell' marked build as failure Finished: FAILURE
09-04
[smb-omadac-v5.10above-win-compile-basic-testing] $ sh -xe C:\Users\ADMINI~1\AppData\Local\Temp\1\jenkins2481184693628970219.sh The system cannot find the file specified FATAL: command execution failed java.io.IOException: CreateProcess error=2, 系统找不到指定的文件。 at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>(ProcessImpl.java:386) at java.lang.ProcessImpl.start(ProcessImpl.java:137) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 10.176.71.22/10.176.71.22:64860 at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1743) at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357) at hudson.remoting.Channel.call(Channel.java:957) at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1060) at hudson.Launcher$ProcStarter.start(Launcher.java:455) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109) at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741) at hudson.model.Build$BuildExecution.build(Build.java:206) at hudson.model.Build$BuildExecution.doRun(Build.java:163) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504) at hudson.model.Run.execute(Run.java:1818) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Caused: java.io.IOException: Cannot run program "sh" (in directory "\home\jenkins\workspace\smb_solution_omada_controller\smb-omadac-v5.10above-win-compile-basic-testing"): CreateProcess error=2, 系统找不到指定的文件。 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at hudson.Proc$LocalProc.<init>(Proc.java:250) at hudson.Proc$LocalProc.<init>(Proc.java:219) at hudson.Launcher$LocalLauncher.launch(Launcher.java:937) at hudson.Launcher$ProcStarter.start(Launcher.java:455) at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1319) at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1272) at hudson.remoting.UserRequest.perform(UserRequest.java:212) at hudson.remoting.UserRequest.perform(UserRequest.java:54) at hudson.remoting.Request$2.run(Request.java:369) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at hudson.remoting.Engine$1.lambda$newThread$0(Engine.java:93) at java.lang.Thread.run(Thread.java:748) Build step 'Execute shell' marked build as failure New run name is '#57_6.0.0.11' Archiving artifacts Started calculate disk usage of build Finished Calculation of disk usage of build in 0 seconds Started calculate disk usage of workspace Finished Calculation of disk usage of workspace in 0 seconds
11-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值