在我安裝、配置好PhoneGap項目的所有依賴後,試圖執行
$ cordova run android
命令時,出現過如下錯誤。
Error: /home/sam/front/redwine/platforms/android/cordova/run: Command failed with exit code 8
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
view rawphonegapError hosted with ❤ by GitHub
cordova build android或cordova emulate android的結果也是一樣。
但其實真正的問題在上面幾行:
[aapt] (skipping file '.jshintrc' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.directory' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] Unable to add '/home/sam/front/redwine/platforms/android/assets/www/bower_components/jquery-mobile/node_modules/grunt-bowercopy/node_modules/bower/node_modules/semver/semver.browser.js.gz': file already in archive (try '-u'?)
[aapt] ERROR: unable to process assets while packaging '/home/sam/front/redwine/platforms/android/ant-build/wine.ap_'
[aapt] ERROR: packaging of '/home/sam/front/redwine/platforms/android/ant-build/wine.ap_' failed
BUILD FAILED
/home/sam/bin/android-sdk-linux/tools/ant/build.xml:932: The following error occurred while executing this line:
/home/sam/bin/android-sdk-linux/tools/ant/build.xml:950: null returned: 1
view rawphonegapError2 hosted with ❤ by GitHub
這是因為項目下有多個node_modules目錄,被重複打包而引發的Command failed with exit code 8問題。
解決辦法是修改platforms/android/build.xml:
<property name="aapt.ignore.assets" value="<dir>node_*" />
將node_modules目錄排除掉,就可以正常執行cordova命令。