-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
插件App编译失败:inconsistent stack height Index 12 out of bounds for length 12 #1196
Comments
首先这个issue反馈的方式特别好,交流开源项目就应该这样基于简单改动可复现的代码。 我分析这个问题应该是javassist的bug。它在addField时,如果有field初始化代码,它需要在构造器里添加几个初始化field的代码。这时: 基于以上分析,我做了兼容修复: 你可以先帮我验证下能否正常工作了。 另外修改后出现了如下的warning,让我不能确定这个兼容是否正确。我在修改后的类中找不到哪里有aload 5。然后也怀疑是不是原本的class就有问题,因为它看起来是经过proguard优化过的。
|
又继续学习了一下。这个问题看起来主要原因还是这个有问题的
通常javac生成的域变量初始化代码是这样的:
可以注意到都是一个变量生成一组aload和putfield的指令。所以它不需要很大的栈。读一个释放一个的概念。 但是 所以说javassist虽然有问题,但可能它就是只针对javac输出的字节码设计的。感觉这段逻辑假设了每条java语句对应的jvm字节码都能清空栈。 #1155 也是这种类不是javac生成的导致的问题。 这么看来javassist对于我们这种需要编辑任意合法JVM字节码的需求来说不是能完全满足的。可能应该考虑在编辑前将class先反编译回java再重新用javac生成较为标准的字节码再编辑。 |
参考https://github.com/shifujun/Shadow/tree/1196,做了兼容,可以正常编译打包了。 修复后,我在https://github.com/cocomikes/Shadow/tree/issue-inconsistent-stack-height这个分支下 :sample-app:dexBuilderPluginDebug有一模一样的WARNING。等我把这个修复发布到内网maven上后,在项目里编译dexBuilderPluginDebug下面就没有以上2条WARNING了。😈 抽空细细研究下javaassist 谢谢大佬,祝好。 |
执行':sample-app:transformClassesWithShadowTransformForPluginDebug'任务时,编译失败
报错日志如下:
`
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: javassist.CannotCompileException: by javassist.bytecode.BadBytecode: (Lorg/webrtc/NetworkMonitorAutoDetect$Observer;Landroid/content/Context;)V in org.webrtc.NetworkMonitorAutoDetect: inconsistent stack height Index 12 out of bounds for length 12
Caused by: java.lang.RuntimeException: javassist.CannotCompileException: by javassist.bytecode.BadBytecode: (Lorg/webrtc/NetworkMonitorAutoDetect$Observer;Landroid/content/Context;)V in org.webrtc.NetworkMonitorAutoDetect: inconsistent stack height Index 12 out of bounds for length 12
at com.tencent.shadow.core.transform_kit.AbstractTransform.debugWriteJar(AbstractTransform.kt:93)
at com.tencent.shadow.core.transform_kit.AbstractTransform.onOutputClass(AbstractTransform.kt:79)
at com.tencent.shadow.core.transform_kit.ClassTransform.output(ClassTransform.kt:144)
at com.tencent.shadow.core.transform_kit.ClassTransform.transform(ClassTransform.kt:186)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:284)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:69)
... 131 more
Caused by: javassist.CannotCompileException: by javassist.bytecode.BadBytecode: (Lorg/webrtc/NetworkMonitorAutoDetect$Observer;Landroid/content/Context;)V in org.webrtc.NetworkMonitorAutoDetect: inconsistent stack height Index 12 out of bounds for length 12
at javassist.CtClassType.modifyConstructors(CtClassType.java:1742)
at javassist.CtClassType.toBytecode(CtClassType.java:1588)
at com.tencent.shadow.core.transform_kit.AbstractTransform.debugWriteJar(AbstractTransform.kt:88)
... 136 more
Caused by: javassist.bytecode.BadBytecode: (Lorg/webrtc/NetworkMonitorAutoDetect$Observer;Landroid/content/Context;)V in org.webrtc.NetworkMonitorAutoDetect: inconsistent stack height Index 12 out of bounds for length 12
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:119)
at javassist.bytecode.MethodInfo.rebuildStackMap(MethodInfo.java:458)
at javassist.bytecode.MethodInfo.rebuildStackMapIf6(MethodInfo.java:440)
at javassist.CtClassType.modifyConstructors(CtClassType.java:1739)
... 138 more
Caused by: javassist.bytecode.BadBytecode: inconsistent stack height Index 12 out of bounds for length 12
at javassist.bytecode.stackmap.Tracer.doOpcode(Tracer.java:81)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:195)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:172)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:116)
... 141 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 12
at javassist.bytecode.stackmap.Tracer.doOpcode148_201(Tracer.java:606)
at javassist.bytecode.stackmap.Tracer.doOpcode(Tracer.java:78)
`
请问出现此问题的原因会是什么呢?shadow-gradle-plugin内javassist转换问题?抑或是NetworkMonitorAutoDetect本身类损坏的问题? @shifujun
附测试demo :
地址: https://github.com/cocomikes/Shadow/tree/issue-inconsistent-stack-height
提交: 31ffdd9
The text was updated successfully, but these errors were encountered: