I love nature photo. Subaru Impreza WRX/Embedded SW/Snowboard/Otaku

Dex cannot parse version 52 byte code

I faced the isuue that Android Studio shows the following error message when I run the app from Android Studio

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.

This error message will be shown if your app is compiled with JDK1.8 and the libraries are compiled with JDK1.7.

How to fix:

Add the following configuration into your build.gradle for all the projects.

for Android plugin:

apply plugin: 'com.android.application'
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7

 for Java plugin:

apply plugin: 'java'

sourceCompatibility = 1.7
targetCompatibility = 1.7