1

Below is the content of my build.gradle for an android studio project :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.nariman.myapplication"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'net.time4j:time4j-calendar:4.20'
    compile 'net.time4j:time4j-olson:4.0'
    testCompile 'junit:junit:4.12'
}

bur I get the below 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.

As you can see , I have already tried adding targetCompatibility and sourceCompatibility , but the issue persist.

I searched and seems there are similar issues reported, but seems now yet find a solution for this.

user3033921
  • 189
  • 1
  • 8
  • 21
  • Duplicate this [post](http://stackoverflow.com/questions/37020413/android-dex-cannot-parse-version-52-byte-code) – Zhang Xiang Nov 17 '16 at 02:05
  • @ZhangXiang as I mentioned in the question, its a similar issue but the dependencies I used are different and also the solution for that post is not working for me. – user3033921 Nov 17 '16 at 02:18

1 Answers1

1

I needed to use the latest version of the time4j , so going back to Java 7 versions of the time4j lib was not an option. I found out there is a sister project for time4j which is for Andriod, its called time4a or time4j-android . So I changed the build.gradle as follow and it solved the issue :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.example.nariman.myapplication"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile group: 'net.time4j', name: 'time4j-android', version: '3.24-2016i'
    testCompile 'junit:junit:4.12'
}

This line solved my issue :

compile group: 'net.time4j', name: 'time4j-android', version: '3.24-2016i'
user3033921
  • 189
  • 1
  • 8
  • 21
  • 1
    That is correct. The Time4j-versions v4.x (you used before) are compiled with Java-8 so just setting compatibility-flags to lower Java-versions will not help. Time4A is the right way for Android, not Time4J. – Meno Hochschild Nov 21 '16 at 12:41