如何在Android项目中使用AntlrV4

huangapple go评论77阅读模式
英文:

How to use AntlrV4 in Android Project

问题

我在我的Android项目中似乎无法让antlr4正常工作,当使用IntelliJ的Antlr4插件时,将词法分析器分配给一个val时会引发此错误:

无法反序列化版本为4的ATN(期望为3)。

我还在我的build.gradle中导入了Antlr4运行时v4.9,如果我没记错的话。Antlr4插件显示它是v4.12?这可能是问题吗?当它说期望3时,我感到困惑。插件不应该生成V4词法分析器和解析器吗?我对Antlr非常陌生,谷歌在寻找解决方法时并没有帮助。

英文:

I cannot seem to get antlr4 working in my android Project, when using the Antlr4 plugin for intellij. When assigning the lexer to a val it throws this error

Could not deserialize ATN with version 4 (expected 3).

I'm also importing the Antlr4 runtime in my build.gradle v4.9 iirc. The Antlr4 plugin says it's v4.12? Could that be the issue? I was thrown off when it said expected 3. Should it not be generating V4 lexer and parser with the plugin? I'm very new to Antlr and Google hasn't been fruitful in my search to solve this.

答案1

得分: 0

感谢kaby76,版本确实是问题所在。插件是4.12版本,因此更新实现为"org.antlr:antlr4-runtime:4.12.0"就解决了问题。

英文:

Thanks to kaby76, the versions were indeed the problem. the plugin is 4.12, so updating the implementation to implementation "org.antlr:antlr4-runtime:4.12.0" did the trick

huangapple
  • 本文由 发表于 2023年5月24日 22:39:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定