Android Studio gradle 构建问题:局部变量类型不匹配
Android Studio gradle build issue: local variable type mismatch
因为我试图在互联网上寻找解决方案,但与我的案例没有太大关系
接下来是问题,构建失败并出现错误:
Error:Uncaught 翻译错误:com.android.dx.cf.code.SimException:局部变量类型不匹配:尝试使用 int 类型的局部变量设置或访问 java.lang.Object 类型的值。这是 .class 忽略局部变量信息的转换工具的症状。
我有 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) 我会遇到构建问题
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-运行 被禁用,因为 proguard 被启用
所以无论我做什么我都无法超越这一点,即使我创建了单独的 proguard 文件(调试文件)
然后放下一个:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontobfuscate
-dontoptimize
-dontpreverify
-ignorewarnings
变得相同,尝试使用:multiDexEnabled true
但仍然没有成功
在这种情况下启用 proguard 我可以构建,正常获取 debug/release 并且除调试外所有工作正常(我需要很多)
这是我连续第二天遇到问题并且无法解决
有人有类似的问题吗?我该如何解决?
P.S。
gradle 堆栈跟踪和调试标志没有给我任何用处,所以没有帮助
如果我对你的问题的理解是正确的,那么你只会在调试版本中禁用 ProGuard 时遇到问题。
这表明您的依赖 jar 之一未正确构建并且包含一个 LocalVariableTable 或 LocalVariableTypeTable 属性不正确有效,导致问题中显示的错误。
启用混淆器后看不到问题的原因是混淆器默认会删除相关属性(除非您添加 -keepattributes xxx 配置)。
要解决这个问题,您需要确定是哪个 jar 导致了这个问题并获取它的正确版本(通过使用 ProGuard 自行处理它以删除 LocalVariable 表或获取更新版本正确构建)。
有时问题是因为某个 jar 已被 ProGuard 优化。已知一种特定的优化技术存在问题,应该对库禁用 (-optimizations !code/allocation/variable)。
我从 SDK Manager 卸载 Google Repository 后出现这种情况,即使我重新安装它,问题仍然存在。
我通过关闭 Android Studio,从文件系统中删除一堆 cache-related 东西,然后 re-opening Android Studio 来修复它。
我删除的一些文件是:
{USERPROFILE}\.gradle
{project}\build
build
{IDE}\tmp
因为我试图在互联网上寻找解决方案,但与我的案例没有太大关系
接下来是问题,构建失败并出现错误: Error:Uncaught 翻译错误:com.android.dx.cf.code.SimException:局部变量类型不匹配:尝试使用 int 类型的局部变量设置或访问 java.lang.Object 类型的值。这是 .class 忽略局部变量信息的转换工具的症状。
我有 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) 我会遇到构建问题
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-运行 被禁用,因为 proguard 被启用
所以无论我做什么我都无法超越这一点,即使我创建了单独的 proguard 文件(调试文件) 然后放下一个:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontobfuscate
-dontoptimize
-dontpreverify
-ignorewarnings
变得相同,尝试使用:multiDexEnabled true 但仍然没有成功 在这种情况下启用 proguard 我可以构建,正常获取 debug/release 并且除调试外所有工作正常(我需要很多)
这是我连续第二天遇到问题并且无法解决 有人有类似的问题吗?我该如何解决?
P.S。 gradle 堆栈跟踪和调试标志没有给我任何用处,所以没有帮助
如果我对你的问题的理解是正确的,那么你只会在调试版本中禁用 ProGuard 时遇到问题。
这表明您的依赖 jar 之一未正确构建并且包含一个 LocalVariableTable 或 LocalVariableTypeTable 属性不正确有效,导致问题中显示的错误。
启用混淆器后看不到问题的原因是混淆器默认会删除相关属性(除非您添加 -keepattributes xxx 配置)。
要解决这个问题,您需要确定是哪个 jar 导致了这个问题并获取它的正确版本(通过使用 ProGuard 自行处理它以删除 LocalVariable 表或获取更新版本正确构建)。
有时问题是因为某个 jar 已被 ProGuard 优化。已知一种特定的优化技术存在问题,应该对库禁用 (-optimizations !code/allocation/variable)。
我从 SDK Manager 卸载 Google Repository 后出现这种情况,即使我重新安装它,问题仍然存在。
我通过关闭 Android Studio,从文件系统中删除一堆 cache-related 东西,然后 re-opening Android Studio 来修复它。
我删除的一些文件是:
{USERPROFILE}\.gradle
{project}\build
build
{IDE}\tmp