Android Studio under Mac system uses gradle command line to package

The bash gradle command not found problem occurs when using the Android Studio command line to package. The reason is that, similar to the environment we configured under the Windows system, gradle is not configured in the Mac. The Terminal window of Android Studio is as follows:


Solution:
(1)
Find the directory where gradle is located, as shown in the figure below, right-click on the Android Studio application -> display package content, open it and follow the Contents->gradle->gradle-xxx->bin path to find gradle.



Then right-click -> show profile, copy the path, similar to:
/Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin, where /Applications/Android is manually entered with \ followed by a space, and the final result is /Applications/ Android\ Studio.app/Contents/gradle/gradle-4.1/bin

(2) Setting the environment variables
On the mac command line, perform the following steps in sequence:
1) cd ~
2) touch .bash_profile
3) open -e .bash_profile

Where touch will be recreated when there is no .bash_profile, open is to open the .bash_profile file, and add the following to the opened file:
export GRADLE_HOME=/Applications/Android\ Studio.app/Contents/gradle/gradle-4.1
export PATH=${ PATH}:${GRADLE_HOME}/bin

The path is what we found in the first step introduction.

4) Command line execution: source .bash_profile to make the modification take effect.

(3) Modify permissions Modify
the permissions of gradle in the bin directory:



Command line input: ls -l to view the permissions, if there is no x permission between gradle and gradle.bat, execute: chmod +x gradle and chmod +x gradle.bat respectively, increase the execution permission.



(4) Test
Close the mac command line terminal and restart Android Studio.
Re-open the mac terminal and Android Studio, enter: gradle -v in the mac terminal, there is output indicating that the configuration is successful.
The gradle command can also be executed in the Terminal of Android Studio.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325721040&siteId=291194637