zoukankan      html  css  js  c++  java
  • 在Android中引入Java8的lambda表达式

    我用的是retrolambda这个插件,下面来说下如何添加它。

    项目地址:https://github.com/evant/gradle-retrolambda

    在根项目的build.gradle中添加这个classpath

    classpath 'me.tatarka:gradle-retrolambda:3.2.0'//retrolambda

    example:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.3'
            classpath 'me.tatarka:gradle-retrolambda:3.2.0'//retrolambda
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }

    然后,在项目的bulid.gradle中添加插件,并让其使用java8

    apply plugin: 'com.android.application'
    apply plugin: 'me.tatarka.retrolambda'
    
    android {
        compileSdkVersion rootProject.compileSdkVersion
        buildToolsVersion rootProject.buildToolsVersion
    
        defaultConfig {
            applicationId "kale.androidframework"
            minSdkVersion rootProject.minSdkVersion
            targetSdkVersion rootProject.targetSdkVersion
            versionCode Integer.parseInt(project.VERSION_CODE)
            versionName project.VERSION_NAME
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    
        lintOptions {
            checkReleaseBuilds false
            // Or, if you prefer, you can continue to check for errors in release builds,
            // but continue the build even when errors are found:
            abortOnError false
        }
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    retrolambda {
        javaVersion JavaVersion.VERSION_1_7
    }
    
    //设置编码  
    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
    }

    如果你用到了多个lib库,需要在每个lib中进行添加:

    apply plugin: 'me.tatarka.retrolambda'
    
    android {
    
    
      compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    
    
    }
  • 相关阅读:
    神经网络 分类: 机器学习 2014-08-12 11:41 87人阅读 评论(0) 收藏
    怎样使用OpenCV进行人脸识别 分类: 计算机视觉(转载) 2014-08-11 16:54 255人阅读 评论(0) 收藏
    machine learning的网站总结 2014-08-10 21:58 91人阅读 评论(0) 收藏
    C程序设计语言习题解答
    Debian下安装vim
    我不能输
    除了爱你还能爱谁
    Linux下配置OpenCV1.0环境
    1:A+B Problem
    3:大整数加法(待复习版)
  • 原文地址:https://www.cnblogs.com/tianzhijiexian/p/4633377.html
Copyright © 2011-2022 走看看