Android Studio Gradle构建问题:局部变量类型不匹配 [英] 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
接下来是问题,构建失败并出现错误: 错误:未捕获的翻译错误:com.android.dx.cf.code.SimException:局部变量类型不匹配:尝试使用int类型的局部变量设置或访问java.lang.Object类型的值.这是忽略局部变量信息的.class转换工具的症状.
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.
我有2个配置
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'
}
}
问题是,如果我关闭debug proguard(minifyEnabled为false),则会遇到构建问题
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.
启用Proguard后,Inta-Run被禁用
Inta-Run is disabled as proguard is enabled
因此,即使我创建了单独的proguard文件(调试一个文件),我也无法克服这一点. 然后放下: -renamesourcefile属性SourceFile -keepattributes SourceFile,LineNumberTable -dontobfuscate -dontoptimize -不要验证 -ignorewarnings
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
获得相同的结果,尝试使用:multiDexEnabled true 但仍然没有成功 在这种情况下,启用了proguard的情况下,我可以进行构建,正常地进行调试/发布以及除调试以外的所有工作(我需要很多东西)
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与stacktrace和debug标志对我没有任何帮助,所以没有帮助
P.S. gradle with stacktrace and debug flags gives me nothing useful so no help
推荐答案
如果我正确理解了您的问题,则只有在调试版本中禁用 ProGuard 时,您才会遇到问题.
If I understand your problem correctly, you are only getting the problem when disabling ProGuard in your debug build.
这表明您的一个依赖罐未正确构建,并且包含无效的 LocalVariableTable 或 LocalVariableTypeTable 属性,导致显示错误问题中.
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.
启用ProGuard后看不到该问题的原因是,ProGuard默认会删除相关属性(除非您添加 -keepattributes xxx 配置).
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).
要解决此问题,您将需要确定引起该问题的jar,并获取正确的版本(通过使用ProGuard自行处理以删除LocalVariable表或获取正确构建的更新版本) ).
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).
有时候,问题出在ProGuard优化的罐子里.已知一种特定的优化技术存在问题,应该对库禁用( -optimizations!code/allocation/variable ).
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).
这篇关于Android Studio Gradle构建问题:局部变量类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!