2016-03-28 64 views
1

Cordova正確安裝,Android SDK也是如此。'ANDROID_HOME'環境變量在linux上與nodejs未定義由cordova

# echo $ANDROID_HOME 
/home/user/android-sdk-linux 

# cordova build android --verbose 
Error: CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. 
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory. 
at /home/user/myApp/platforms/android/cordova/lib/check_reqs.js:225:8 
at _fulfilled (/home/user/myApp/platforms/android/cordova/node_modules/q/q.js:834:54) 
at self.promiseDispatch.done (/home/user/myApp/platforms/android/cordova/node_modules/q/q.js:863:30) 
at Promise.promise.promiseDispatch (/home/user/myApp/platforms/android/cordova/node_modules/q/q.js:796:13) 
at /home/user/myApp/platforms/android/cordova/node_modules/q/q.js:857:14 
at runSingle (/home/user/myApp/platforms/android/cordova/node_modules/q/q.js:137:13) 
at flush (/home/user/myApp/platforms/android/cordova/node_modules/q/q.js:125:13) 
at process._tickCallback (node.js:355:11) 
at Function.Module.runMain (module.js:503:11) 
at startup (node.js:129:16) 

好吧......通過檢查的NodeJS變量:

# node 
> process.env['ANDROID_HOME'] 
'~/android-sdk-linux' 

一切似乎都很好... 好吧......編輯文件「家庭/用戶/對myApp /platforms/android/cordova/lib/check_reqs.js「(從上面的錯誤中)加入下一行:

if (!process.env['ANDROID_HOME']) { 
    console.log(process.env['ANDROID_HOME']); 
    throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' + 
      'Failed to find \'android\' command in your \'PATH\'. Try update your \'PATH\' to include path to valid SDK directory.'); 
} 

結果是:

# cordova build android --verbose 
Executing "before_build" hook for all plugins. 
... 
Executing "after_prepare" hook for all plugins. 
Executing "before_compile" hook for all plugins. 
**undefined** 
Error: CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. 

如何與和的NodeJS科爾多瓦解決這個問題?

回答

0

選項1

窗戶

我的電腦上點右鍵 - >屬性 - >高級系統設置 - >環境變量

現在在系統變量編輯路徑;/yourSdkHome /工具/ youSdkHome /平臺的工具。

選項2

在Windows機器,打開命令提示和輸入每個的這個命令逐個

set ANDROID_HOME=C:\android-sdk-windows 
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools 

在MAC機,開放式終端並輸入這些逐個

export ANDROID_HOME=//android-sdk-macosx export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools 

注 - C:\ android-sdk-windows應該被您的機器中Android SDK的路徑所取代。

應該被您的機器中Android SDK的路徑所取代。

在MAC機

,如果安裝位置是〜/ ADT-束-MAC-x86_64的/ SDK

第一行應是

export ANDROID_HOME=~/adt-bundle-mac-x86_64/sdk 
+0

這就是所有完成的,問題的NodeJS! 系統中定義的ANDROID_HOME變量,但不能用js文件讀取。 – user1356144