(一)找到gradle的路徑
注意:android studio應用顯示包內容,將路徑拿到,記得 Android 後面的空格要加 \ 轉義
(二)配置環境變量
啓動終端Terminal
如果首次配置環境變量需要創建配置文件
//創建配置文件
touch .bash_profile
//打開配置文件
open -e .bash_profile
//編輯配置文件 在配置文件.bash_profile中添加如下代碼 (export GRADLE_HOME=gradle路徑)
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-4.6
export PATH=${PATH}:${GRADLE_HOME}/bin
//更新配置文件
source .bash_profile
執行 gradle -v 如果沒有增加權限會出現如下提示
-bash: /Applications/Android Studio.app/Contents/gradle/gradle-4.6/bin/gradle: Permission denied
(三)增加權限
chmod +x /Applications/Android\ Studio.app/Contents/gradle/gradle-4.6/bin/gradle