android studio使用JDK8

吐嘈:麻蛋,我电脑CSDN又抽风了~~~

最近不知道在忙什么,好久没更新了,发现也没什么想分享的。还是要坚持写Blog!!

今天看了一个别人的项目,用的JDK8,不知道什么原因,一直报我错,但我电脑配置是正常的啊 - 我之前有工程用了JDK8 - 所以这里记录一下JDK8的使用方法笔记,解惑自己猜疑

如标题,我只是想使用JDK8,新建一个android studio工程,配置如下

  • build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0-alpha5'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

添加classpath 'me.tatarka:gradle-retrolambda:3.2.5'maven { url "https://jitpack.io" }

  • app/build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.xuie.jdk8_demo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}


compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
}

添加

apply plugin: 'me.tatarka.retrolambda'

1
2
3
4
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
  • 代码测试
1
2
fab.setOnClickListener(view->Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show());

上张截图,原先的写法多余部分已经为成为提示无意义

文章作者: 二十I邊界
文章链接: https://xuie0000.com/post/2016-04-09-2019/android-studio使用JDK8.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 二十I邊界