BUG: Android Kotlin dex transformation error

February 2016

Today I got strange error on HelloWorld-like project:

Error:Execution failed for task ‘:app:transformClassesWithDexForDebug’.
> 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: org.gradle.process.internal.ExecException: Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java” finished with non-zero exit value 1

Then I tried to build project with logs to see:

./gradlew clean && ./gradlew –stop && ./gradlew –debug assembleDebug

Among the others it gave the next lines:

15:53:24.976 [INFO] [org.gradle.api.Project] Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type com.expertoption.popup.HeaderInfo[] using a local variable of type android.widget.ExpandableListView. This is symptomatic of .class transformation tools that ignore local variable information.

15:53:24.976 [INFO] [org.gradle.api.Project] Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type com.expertoption.popup.HeaderInfo[] using a local variable of type android.widget.ExpandableListView. This is symptomatic of .class transformation tools that ignore local variable information.

When I exclude some areas of my code, it turned out than the cause of that bug was the following code:

 setAdapter(object : BaseExpandableListAdapter() {

    var sampleData = arrayOf( /* Some data */ )

I don’t know the reason, but if you want to get rid off it you have to use listOf instead of arrayOf.

setAdapter(object : BaseExpandableListAdapter() {

    var sampleData = listOf( /* and here we're! :-) */ )

Another but if you need to use Array, another solution is using getters:

val sampleData: Array<HeaderInfo>
  get() = arrayOf()

Don’t forget to rebuild you project and restart gradle daemon:

./gradlew clean && ./gradlew –stop && ./gradlew –debug assembleDebug

Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *