Compile with Proguard Gives Simexception: "Local Variable Type Mismatch"

Compile with Proguard gives SimException: local variable type mismatch

The actual Proguard part finishes, but then dex cannot convert the resulting bytecode anymore. Dex considers the LocalVariableTable incorrect. Eric Lafortune is the better source to explain why (see his answer).

The problem goes away if you not only don't obfuscate, but also skip the optimization step (-dontoptimize). But you want to have this for the size reduction. Another way to solve it is to drop the debug flags in javac and in dex. Only problem is that then you wouldn't have proper stacktraces either. You will get stacktrace lines without source file info or line numbers such as:

net.lp.collectionista.domain.items.book.BookItem.getCoverImageForFormField(Unkno‌​wn Source)

You can do this by adding debug="false" in the javac tag in the ant main-rules.xml (you may want to copy the part to a build.xml first). This will set a flag javac -g:none. You also have to configure dex and this is harder to do in the provided ant template. I copied the dex-helper macro, made sure it was being used, and added a condition tag surrounding the dex calls:

        <echo>Converting compiled files and external libraries into ${intermediate.dex.file}...</echo>
<if condition="debug">
<then>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=${intermediate.dex.file}" />
<extra-parameters />
<arg line="${verbose.option}" />
<arg path="${out.dex.input.absolute.dir}" />
<path refid="out.dex.jar.input.ref" />
<external-libs />
</apply>
</then>
<else>
<apply executable="${dx}" failonerror="true" parallel="true">
<arg value="--dex" />
<arg value="--output=${intermediate.dex.file}" />
<arg value="--no-locals" /><!-- otherwise dex fails on the proguard bytecode -->
<extra-parameters />
<arg line="${verbose.option}" />
<arg path="${out.dex.input.absolute.dir}" />
<path refid="out.dex.jar.input.ref" />
<external-libs />
</apply>
</else>
</if>

It's the --no-locals that does it.

To mitigate the loss of stacktrace information you can use, respectively for line number information and class and method names information:

-keepattributes SourceFile, LineNumberTable
-keep,allowshrinking,allowoptimization class * { <methods>; }

This way you can do partial obfuscation, and still have equivalent good stacktraces. I still suggest you create and keep the mapping files upon release though.

On top of all this you shouldn't specify -keepattributes LocalVariableTable,LocalVariableTypeTable and equally -keepparameternames (if you do obfuscate, this by itself might get you into troubles as well). Note that the second implies the first, even though it may not be clear from its name that it affects attributes.

Personally, and in view of other problems with Proguard, I chose to do the obfuscation but mitigate the loss of stacktrace information. I haven't tried @plowman's proposal yet.

For more details you can find my version controlled project files here:

  • proguard.cfg

  • build.xml

Android Studio gradle build issue: local variable type mismatch

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).

Dalvik - local variable type mismatch when adding java file to project - Without proguard

Turns out it was an eclipse plugin that did it - CodePro BY GOOGLE!
Their code coverage tool somehow caused the above error (maybe has something to do with emma, but that's just a guess).

ProGuard SimException

The problem might be related to a specific optimization of ProGuard.
You can disable it like that:

-optimizations !code/allocation/variable

Furthermore you can also remove the LocalVariableTable and LocalVariableTypeTable attributes which do not seem to be updated properly (and are not needed in an application anymore). For this you would need to enable obfuscation though and then use something like:

-keepattributes !LocalVariable*,**

This rule would keep all attributes but the LocalVariable related ones.

The obfuscation problem with libGDX might be solved by this rule:

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;
}

Proguard error log giving wrong library/class name

I manage to get the correct library names by changing the build variants from release to debug.

Error local variable type mismatch, in Xamarin.Android

In case it my help someone else i have finally found the solution.

It turns out the compiler was the problem.

I went to the Xamarin.Android Properties, then went to the Android Options tab. In the Dex compiler field I selected d8.

Android build with Proguard DX SimException local 0000: invalid

I've deleted the option :

-optimizationpasses 5

in proguard.cfg generated by android sdk

and it works.

I don't know what exactly this option's doing.



Related Topics



Leave a reply



Submit