MAC JAVA8环境变量配置
下载JAVA8 安装
JAVA8
打开终端运行
/usr/libexec/java_home -V
运行结果:
Matching Java Virtual Machines (1):
1.8.0_112, x86_64: "Java SE 8"
/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
- 检查JDK目录是否齐全:
ls -l /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/
//运行结果
-rwxrwxr-x 1 root wheel 103712 10 1 2016 appletviewer
-rwxrwxr-x 1 root wheel 103712 10 1 2016 extcheck
-rwxrwxr-x 1 root wheel 103712 10 1 2016 idlj
-rwxrwxr-x 1 root wheel 103712 10 1 2016 jar
-rwxrwxr-x 1 root wheel 103712 10 1 2016 jarsigner
-rwxrwxr-x 1 root wheel 103632 10 1 2016 java
-rwxrwxr-x 1 root wheel 103712 10 1 2016 javac
-rwxrwxr-x 1 root wheel 103712 10 1 2016 javadoc
-rwxrwxr-x 1 root wheel 2293 9 23 2016 javafxpackager
-rwxrwxr-x 1 root wheel 103712 10 1 2016 javah
-rwxrwxr-x 1 root wheel 103712 10 1 2016 javap
-rwxrwxr-x 1 root wheel 2293 10 1 2016 javapackager
-rwxrwxr-x 1 root wheel 103712 10 1 2016 jcmd
。。。。。。。。。。。。。。
打开/.bash_profile进行环境变量配置
JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8)
export JAVA_HOME=$JAVA_8_HOME
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
检查是否成功
java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)
gradle-retrolambda配置
打开工程build.gradle添加:
classpath 'me.tatarka:gradle-retrolambda:3.6.1'
apply plugin: 'me.tatarka.retrolambda'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'me.tatarka:gradle-retrolambda:3.6.1'--->这里
}
}
allprojects {
repositories {
jcenter()
apply plugin: 'me.tatarka.retrolambda'--->这里
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
打开MoDule配置:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
测试:
btn.setOnClickListener(v ->Toast.makeText(this,btn.getText().toString(),Toast.LENGTH_LONG).show());