开发者

Embed Groovy in an Android Java App

开发者 https://www.devze.com 2023-04-08 04:24 出处:网络
Basically, I need to run Groovy Scripts to manipulate Java objects, and GroovyShell / GroovyScriptEngine seems to be the best way to do so. Is it possible to embed Gr开发者_运维问答oovy inside a Java

Basically, I need to run Groovy Scripts to manipulate Java objects, and GroovyShell / GroovyScriptEngine seems to be the best way to do so. Is it possible to embed Gr开发者_运维问答oovy inside a Java App? I tried placing the groovy-all-1.8.2.jar into my Android Java App's libs folder, referenced it then hit compile but I got a bunch of errors.

How do I do this?


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...


In near future it will be possible: http://skillsmatter.com/podcast/home/groovy-android/


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!


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).


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.


A better choice for running scripts on Android is SnapScript. It does not rely on Bytecode and is fully supported on Android.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号