Modify the JDK version used by Android Studio on Mac.

Source: Internet
Author: User

Modify the JDK version used by Android Studio on Mac.
Modify the JDK version used by Android Studio on Mac

@ Author ASCE1885

Recently, the project has moved from the Eclipse + Ant build mode to the Android Studio + Gradle build mode. The natural JDK version number has also been upgraded from JDK 6 to JDK 7, but later we found that because we are an SDK project, in the end, it will be provided to a third party in the form of a JAR package. This will cause a problem. If we use JDK 7 to compile the JAR package, and the third-party compiling environment uses the old JDK 6, the following occurs during project Compilation:

Unsupported major.minor version 51.0

Therefore, we need to reduce the Android Studio project compiling environment from JDK 7 to JDK 6. The following is the modification record.

Path of JDK of Mac system

By default, the default installation directories for different Mac system JDK versions are slightly different. The installation directories for JDK 6, JDK 7, and JDK 8 are as follows:

/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/Library/Java/JavaVirtualMachines/jdk1.7.0.jdk/Contents/Home/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home
Android Studio Modification

Click File-Other Settings-Default Project Structure of Android Studio:

Open the Project Structure dialog box, in which you can modify the path of Android SDK and JDK:

Environment Variable Modification

After the above modification, we will use the modified JDK 6 when compiling on the Android Studio UI interface, however, when we enter java-version in Terminal to view the current JDK version information, we will find that it is still the previous JDK 7 version. The possible reason is that the JAVA_HOME environment variable is set in the system, therefore, we need to modify it here.

Open Terminal and enter vim ~ /. Bash_profile: open the file with the following content:

As you can see, the environment variable is indeed in the previous JDK 7 version, and you can point it to the installation path of JDK 6. Then reload the profile to make it take effect:

source ~/.bash_profile
Jenkins Modification

The automated compilation uses Tomcat + Jenkins. Jenkins is easy to modify. On the Jenkins homepage, click [System Management]-[system settings] and find the following JDK settings options to modify them:

After the modification is complete, restart Tomcat and you will find that the Jenkins page access fails because the Jenkins version we use only supports JRE7 at the lowest. The official website is as follows:

In the environment variable step, we have reduced the JDK version from JDK7 to JDK6. In this case, we can modify the JRE_HOME parameter of Tomcat to open the bin/catalina under the Tomcat installation directory. sh (because I am using Mac, switch to catalina in Windows. bat), search for the JRE_HOME parameter, create it if it does not exist, and assign it to the JDK 7 directory on the computer:

JRE_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.