Search code examples
androidgradleproguard

Android Studio gradle build issue: local variable type mismatch


As I tried to find solution on internet but nothing too much related to my case

Issue is next, build fails and getting error: Error:Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.

I have 2 configs

buildTypes {
debug {
    debuggable true
    minifyEnabled true
    signingConfig signingConfigs.defaultKey
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

release {
    debuggable false
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

}

issue is if I turn off debug proguard (minifyEnabled false) I get issue with build

Error:Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.
Error:Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type int using a local variable of type android.util.SparseIntArray. This is symptomatic of .class transformation tools that ignore local variable information.

Inta-Run is disabled as proguard is enabled

So whatever I do I can't get past this point, even if I create separate proguard file (debug one) and put next:

-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontobfuscate
-dontoptimize
-dontpreverify
-ignorewarnings

getting same, tried with : multiDexEnabled true but still no success In this case with proguard enabled I can build, getting debug/release normally and all works EXCEPT debug (what I need a lot)

And this is 2nd day in row that I having issue with it and can' solve it Have somebody have similar issues? How I could solve it?

P.S. gradle with stacktrace and debug flags gives me nothing useful so no help


Solution

  • If I understand your problem correctly, you are only getting the problem when disabling ProGuard in your debug build.

    This is an indication that one of your dependent jars has not been built correctly and contains a LocalVariableTable or LocalVariableTypeTable attribute that is not valid, resulting in the error as shown in the question.

    The reason that you do not see the issue when ProGuard is enabled is because ProGuard will remove the relevant attributes by default (unless you add a -keepattributes xxx configuration).

    To resolve this issue, you will need to identify which jar is responsible for the problem and get a proper version of it (either by processing it yourself with ProGuard to remove the LocalVariable tables or by getting an updated version that is correctly built).

    Sometimes the problem is because of a jar that has been optimized by ProGuard. One specific optimization technique is known to have issues, and should be disabled for libraries (-optimizations !code/allocation/variable).