2016-11-17 50 views
1

下面是我的build.gradle的一个机器人工作室项目内容:Andrioid工作室 - 错误字节码转换到DEX,原因:地塞米松无法解析版本52字节代码

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' 
} 

钻我得到下面的错误:您可以看到,我已经尝试添加targetCompatibility和sourceCompatibility,但问题仍然存在。

我搜索,似乎有类似的问题报告,但似乎现在还没有找到解决方案。

+0

复制这个[文章](http://stackoverflow.com/questions/ 37020413/android-dex-can-parse-version-52-byte-code) –

+0

@张翔正如我在问题中提到的那样,它有一个类似的问题,但我使用的依赖关系是不同的,并且该帖子的解决方案也不适用我。 – user3033921

回答

1

我需要使用最新版本的time4j,因此回到time4j lib的Java 7版本不是一个选项。 我发现有一个time4j的姊妹项目是Andriod,它叫做time4a或time4j-android。所以我改变了的build.gradle如下,它解决了这个问题:

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' 
} 

这行解决了我的问题:

compile group: 'net.time4j', name: 'time4j-android', version: '3.24-2016i' 
+1

这是正确的。 Time4j版本v4.x(以前使用过)是用Java-8编译的,所以只需将compatibility-flags设置为较低的Java版本将无济于事。 Time4A是Android的正确方式,而不是Time4J。 –

+0

@MenoHochschild是你的权利 – user3033921