Android Studio 3以上内置支持Java 8的相关配置

  • Post author:
  • Post category:java


Error:Error converting bytecode to dex:Cause: Dex cannot parse version 52 byte code.This is caused by library dependencies that have been compiled using Java 8 or above.If you are using the ‘java’ gradle plugin in a library submodule add。targetCompatibility = ‘1.7’ ,sourceCompatibility = ‘1.7’

以上报错则为java8编译的jar包,因为as环境没有升级,导致报错,以下为解决方法:


配置

1、升级Android的Gradle插件

在项目的build.gradle修改为

buildscript {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        google()      
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
}

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


在app的build.gradle文件中添加以下配置

android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

加载同步即可解决!!!!



版权声明:本文为DexLins原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。