简体   繁体   中英

Java 1.7 compatibility for a library in android studio

I want to use this library in my android studio project but when I add it into project using gradle it show the following error

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' to that submodule's build.gradle file.

It seems it is because of java 1.7 compatablility but I have no idea how to fix it. Android studio suggests to add targetCompatibility = '1.7' sourceCompatibility = '1.7' to that submodule's build.gradle but how can I add it into gradles dependencies section?

You should use VERSION_1_8 instead of VERSION_1_7

Install JDK 1.8

You should add this

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

FYI

Before use 1_8 please read Use Java 8 Language

To enable Java 8 language features and Jack for your project, enter the following in your module-level build.gradle file:

android {
  ...
  defaultConfig {
    ...
    jackOptions {
      enabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

Clean-Rebuild and RUN

Version 52 is actually Java 8. The library was compiled without Java 7 compatibility, so it cannot be used if you are targeting Java 7 or lower.

I see that there's an open issue about it on their GitHub. It might be a problem with this versions only, so you might try using a previous version until they fix the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM