gpt4 book ai didi

Android Studio gradle 构建问题 : local variable type mismatch

转载 作者:行者123 更新时间:2023-12-03 10:14:37 25 4
gpt4 key购买 nike

当我试图在互联网上找到解决方案时,但与我的情况没有太多相关

接下来是问题,构建失败并出现错误:错误:未捕获的翻译错误: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'
}

}

问题是,如果我关闭调试混淆器(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.

由于启用了 proguard,Inta-Run 被禁用

所以无论我做什么我都无法超越这一点,即使我创建单独的 proguard 文件(调试一个)并放置下一个:

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

变得相同,尝试使用:multiDexEnabled true但仍然没有成功在这种情况下,启用混淆器后,我可以构建,正常进行调试/发布,并且除了调试(我非常需要)之外的所有工作

这是我连续第二天遇到问题并且无法解决它有人有类似的问题吗?我该如何解决这个问题?

附注带有堆栈跟踪和调试标志的 gradle 没有给我任何有用的东西,所以没有帮助

最佳答案

如果我正确理解您的问题,那么您只有在调试版本中禁用 ProGuard 时才会遇到问题。

这表明您的某个依赖 jar 尚未正确构建,并且包含无效的 LocalVariableTableLocalVariableTypeTable 属性,从而导致如图所示的错误在问题中。

启用 ProGuard 后看不到问题的原因是 ProGuard 默认会删除相关属性(除非您添加 -keepattributes xxx 配置)。

要解决此问题,您需要确定哪个 jar 导致了该问题并获取它的正确版本(通过使用 ProGuard 自行处理以删除 LocalVariable 表,或者获取正确构建的更新版本)。

有时问题是由经过 ProGuard 优化的 jar 引起的。已知一种特定的优化技术存在问题,应该对库禁用(-优化!代码/分配/变量)。

关于Android Studio gradle 构建问题 : local variable type mismatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39331765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com