将 Groovy 嵌入 Android Java 应用程序
基本上,我需要运行 Groovy 脚本来操作 Java 对象,而 GroovyShell / GroovyScriptEngine 似乎是最好的方法。是否可以将 Groovy 嵌入到 Java 应用程序中?我尝试将 groovy-all-1.8.2.jar 放入我的 Android Java 应用程序的 libs 文件夹中,引用它然后点击编译,但出现了一堆错误。
我该怎么做?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不相信这会起作用。 Groovy 将脚本转换为字节码,由于 Dalvik 字节码与 Groovy 期望的 Java 字节码不同,我相信它会出现问题...
Discobot 已经复活 ,并且正在取得巨大进展,因此希望就在眼前。
但今天这对你没有帮助......
I don't believe this will work. Groovy converts scripts to bytecode, and as the Dalvik bytecode is different to the Java bytecode that Groovy expects, I believe it will have problems...
The Discobot from a few years ago has been resurrected though, and great progress is being made so there is hope on the horizon.
But that doesn't help you today...
在不久的将来,这将是可能的: http://skillsmatter.com/podcast/home/groovy-安卓/
In near future it will be possible: http://skillsmatter.com/podcast/home/groovy-android/
我很快就找到了。
您可以从 http://melix.github.io/blog/2014 找到解决方案/06/grooid.html。
检查一下 http://glaforge.appspot.com/article/groovy-2-3-3-and-groovy-2-4-beta-1-with-android-support 也!
I have found it recelty.
You can find the solution from http://melix.github.io/blog/2014/06/grooid.html.
Check it http://glaforge.appspot.com/article/groovy-2-3-3-and-groovy-2-4-beta-1-with-android-support too!
自 09/2011 以来,Discobot 似乎陷入了困境。最后的结果似乎是:大部分有效,但这非常慢。
Groovy 2.0 现已发布,Guillaume Laforge(内部人士)说它可以提供帮助 -特别是因为 Groovy 2.0 的 @CompileStatic 新功能。从那时起,Groovy 2.0.1...2.0.4,看起来静态编译 修复了很多错误。
但目前,在 Groovy 的官方网站上,并没有讨论 Android,似乎没有人真正负责(参见 wiki 和 wiki)。
Since 09/2011, Discobot seems to be stuck. The last results seem to be : most of it works, but this is very slow.
Groovy 2.0 is out now, and Guillaume Laforge (insider) says it could helps - especially because of the @CompileStatic new feature of Groovy 2.0. Since then, Groovy 2.0.1...2.0.4, it looks that static compilation got a lot of bugfixes.
But for now, on the official website of Groovy, Android is not discussed, nobody seems to really be in charge (see wiki and wiki).
这是您想要实现的目标的示例。 https://github.com/melix/grooidshell-example
它非常慢,因为它必须首先在android设备上编译为class文件,然后将它们转换为dex,但它会完成你正在寻找的东西。
Here is an example of what you are trying to accomplish. https://github.com/melix/grooidshell-example
It is pretty slow since it has to first compile to class files on the android device and then convert them to dex, but it will accomplish what you are looking for.
在 Android 上运行脚本的更好选择是 SnapScript。它不依赖于字节码,并且在 Android 上完全支持。
A better choice for running scripts on Android is SnapScript. It does not rely on Bytecode and is fully supported on Android.