upgrading java 8 to 11 with brew for Android on Mac
1. Check the version
$/usr/libexec/java_home -V Matching Java Virtual Machines (1): 1.8.0_60 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
2. Update brew
brew update
3. Add the casks tap.
brew tap homebrew/cask-versions
4. Install java11 with, replace java11 with java12, java13, java17, etc for other java versions.
brew install java11
5. After it’s installed, it will show some instruction such as this.
For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk openjdk@11 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula. If you need to have openjdk@11 first in your PATH, run: echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> /Users/username/.bash_profile For compilers to find openjdk@11 you may need to set: export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
6. Per the instruction, you want to add something like the following to your .bash_profile, make sure the jdk path is correct on your machine.
alias java8='export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home' alias java11='export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home' # default to Java 11 java11
7. Apply the changes made in .bash_profile
source ~/.bash_profile
8. Check java version and you should see java 11 is being used. To use to java8, run java8.
$java -version openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment Homebrew (build 11.0.12+0) OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)
9. Configure Android Studio to use the newly installed java11.
- Preferences (Settings)
- Build, Execution, Deployment
- Build Tools
- Gradle
- Gradle JDK
- Select JDK 11
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts