0

I am encountering the error of converting Bytecode to dex with the following trace.

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:Execution failed for task ':app:transformClassesWithDexForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
Error:1 error; aborting

I know this is due to thoughtworks xstream library used by robolectric where version 1.4.8 is built for jdk 1.8 and it does not support my project. Trying to use Robolectric for Instrumentation Tests by adding dependency as follows,

androidTestCompile ("org.robolectric:robolectric:3.1.2")

Is there any workaround to solve this and run the tests ?

Ashik Vetrivelu
  • 1,021
  • 1
  • 9
  • 24
  • this might help http://stackoverflow.com/questions/37236819/android-studio2-1-1-april-28-2016-strange-error-converting-bytecode-to-dex-de Also do Clean and Build following Make Project – pooja Aug 31 '16 at 09:27
  • It does not work. Throws duplicate entry error for AbstractComponentComposer – Ashik Vetrivelu Aug 31 '16 at 09:56
  • But why do you need Robolectric for instrumentation tests? It's meant to be used for regular java testing style. Will changing `androidTestCompile` to `testCompile` fix the issue? – Geralt_Encore Aug 31 '16 at 10:07
  • Downgrade Robolectric version to 3.0.0 – piotrek1543 Sep 03 '16 at 21:19

0 Answers0