Mac AndroidStudio development environment construction

Mac AndroidStudio development environment construction

1. Configure environment variables on Mac

insert image description here

Execute open ~/.bash_profile (this file is a configuration environment variable).
If there is no prompt,
execute touch ~/.bash_profile to create it.
After opening the file,
add jdk and android sdk.
The reference blue part needs to replace the corresponding content
#jdk
export JAVA_HOME=/Library/ Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
export PATH= JAVAHOME / bin : JAVA_HOME/bin:JAVAHOMR / bin:PATH
export CLASSPATH=.: J A V A H O M E / l i b / d t . j a r : JAVA_HOME/lib/dt.jar: JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
#android sdk
export ANDROID_HOME=/Users/XXXX/Library/Android/sdk
export PATH= P A T H : {PATH}: PATH:{ANDROID_HOME}/tools
export PATH= P A T H : {PATH}: PATH: {ANDROID_HOME}/platform-tools
2. Execute the source command on the command line:
source ~/.bash_profile
Note:
The Mac command line needs to be executed once for each window to take effect, otherwise an error may be reported.

3. Configure SSH Key
To generate ssh key on mac, you can refer to the command: "ssh-keygen -t rsa -C "[email protected]""; press Enter to generate it, and check the ssh key through the command: cat ~/ .ssh/id_rsa.pub

4. Download code

5. Use AndroidStudio to run the project

6. Notes on AndroidStudio configuration
1. SDK path configuration
Open the project structure
insert image description here

Configure jdk as the java_home configured in your environment variable
2. Execute the gradle command through the terminal.
When executing the gradle command through the console, it may fail,
such as the packaging command ./gradlew assembleDebug, ./gradlew assembleRelease, etc., it will prompt "Kotlin could not find the required JDK tools in the Java installation", this is because after the Mac OS is upgraded, jdk will be automatically carried, but the content is incomplete. Executing the gradle command through the console will switch to the jdk that comes with the mac, resulting in Failed.
First execute the /usr/libexec/java_home -V command to check whether there are multiple jdk locally.

insert image description here

Solution 1
Simply delete or rename the redundant jdk
Execute the command
cd /Library/Internet\ Plug-Ins/
mv JavaAppletPlugin.plugin DELETED-JavaAppletPlugin.plugin

Solution 2
Configure org.gradle.java.home in gradle.properties and specify the jdk directory used by gradle compilation

org.gradle.java.home = /Library/Java/JavaVirtualMachines/jdk1.8.0_291.jdk/Contents/Home

Guess you like

Origin blog.csdn.net/adayabetter/article/details/130339399