2016-11-17 43 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

相關問題