android studio使用JDK8

来源:互联网 发布:双头龟一只多少钱淘宝 编辑:程序博客网 时间:2024/06/06 17:31

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

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

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

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

  • build.gradle
// 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
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'

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

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

0 0
原创粉丝点击