Android Studio gradle build issue: local variable type mismatch

和自甴很熟 提交于 2019-12-08 01:54:49

问题


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


回答1:


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




回答2:


This happened after I uninstalled Google Repository from SDK Manager, and the problem continued even after I reinstalled it.

I fixed it by closing Android Studio, deleting a bunch of cache-related things from the file system, and then re-opening Android Studio.

Some of the files I deleted were:

  • {USERPROFILE}\.gradle
  • {project}\build
  • build
  • {IDE}\tmp


来源:https://stackoverflow.com/questions/39331765/android-studio-gradle-build-issue-local-variable-type-mismatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!