Android studio 2.3.1将字节码转换为dex时出错
问题描述:
我刚刚将此依赖项(compile'com.google.guava:guava:21.0')添加到gradle中,当我尝试运行该应用程序时,出现下面的错误。我试图清理项目,但它并没有帮助me.Can有人请帮我解决Android studio 2.3.1将字节码转换为dex时出错
错误:
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.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\Zabit\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar' to 'E:\Ohxee\app\build\intermediates\transforms\dex\debug\folders\1000\10\guava-21.0_c8c319a8080e46e7bfc8243fe4c3e3b2a6150f16'
的build.gradle(APP):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.xxxx.xxx"
minSdkVersion 16
targetSdkVersion 25
multiDexEnabled true
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.borax12.materialdaterangepicker:library:1.9'
compile 'com.iceteck.silicompressorr:silicompressor:1.1.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.patrickpissurno:ripple-effect:1.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.android.gms:play-services-maps:10.2.4'
testCompile 'junit:junit:4.12'
compile 'com.roughike:bottom-bar:1.4.0.1'
compile 'com.github.darsh2:MultipleImageSelect:3474549'
compile 'com.google.guava:guava:21.0'
compile 'com.android.support:multidex:1.0.1'
}
答
第一清洁项目
不是试图使项目
现在运行项目模块
答
的问题是与番石榴/ Java版本。从番石榴版本21起,根据documentation,要求是Java 8。
Android Studio(和Android在这一点上)仍然在JDK 7上,并带有一些JDK 8功能。谢天谢地,他们根据this提供番石榴味。
基本上所有你需要做的是:
compile 'com.google.guava:guava:22.0-android'
希望这有助于。
还是同样的错误 – jobin
如果你有一个子模块的项目,你能添加此 compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } 试试你的build.gradle内(项目/模块) –
我补充说,现在我得到了这个错误:(23,0)无法找到方法compileOptions()的参数[build_58jzqqrivbdfgfchs104vwi47 $ _run_closure2 @ 3c095506]项目':app'的类型org.gradle.api.Project。 Open File – jobin