Cordova android build fails immediately [Error: spawn EACCES]

在学习Cordova时,build android平台时,遇到spawn EACCES错误,在网上找了几篇帖子,都说是权限问题,按照描述更改了各种提到的文件权限,始终没有解决。最后在stackoverflow找到了最好的解决方法。
本人用的时OS X系统,其他系统应该相同。另外本人机器上同时安装了android studio 3.0 preview和2.3两个版本,所以有两个gradle的版本,系统默认会调用最新版/最后安装的版本,所以使用以下命令可以找出具体出问题的:

cordova build –release –verbose android

输出如下:

No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /Users/xxxx/Dev/workspace/cordova_ws/hello/platforms/android/res/xml/config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/assets/www
Wrote out android application name "HelloWorld" to /Users/xxxx/Dev/workspace/cordova_ws/hello/platforms/android/res/values/strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.0): 10000
Wrote out Android package name "com.example.hello" to /Users/xxxx/Dev/workspace/cordova_ws/hello/platforms/android/src/com/example/hello/MainActivity.java
This app does not have launcher icons defined
This app does not have splash screens defined
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=/Users/xxxx/Library/Android/sdk
JAVA_HOME=/Users/xxxx/Dev/JDK
Running command: "/Applications/Android Studio 3.0 Preview.app/Contents/gradle/gradle-4.1/bin/gradle" -p /Users/xxxx/Dev/workspace/cordova_ws/hello/platforms/android wrapper -b /Users/xxxx/Dev/workspace/cordova_ws/hello/platforms/android/wrapper.gradle
Error: spawn EACCES

然后在输出信息中(往往是最后几行)找到最后执行的文件,此处为

Running command: "/Applications/Android Studio 3.0 Preview.app/Contents/gradle/gradle-4.1/bin/gradle" -p /Users/xxxx/Dev/workspace/cordova_ws/hello/platforms/android wrapper -b 

修改此gradle执行文件的权限

 chmod 777 <file> 

再执行

cordova build android

猜你喜欢

转载自blog.csdn.net/leon_founder/article/details/78221980