简体   繁体   中英

Adding scripting to an android app

I have an android app that users should be able extend using scripts. That's the plan anyway. Users can write scripts which are saved into a folder on their flash and accessed from a menu in the app. The scripts are loaded up and called based on certain events in the application. The application will expose helper methods and objects into the script's context so it can tap functionality in the app in a controlled way.

Therefore my requirements are:

  • Low disk / memory footprint
  • Fast startup
  • Android compatible
  • Reasonable parsing / error reporting
  • Simple, sane syntax preferably a dialect of a popular language, eg Basic, JS, Python etc.
  • Language must support arrays, associative arrays, double precision floats, string manipulation. It doesn't need network access or much else.
  • Clean load & unload of scripts
  • Something that accommodates an event driven model
  • Security / sandbox model which prevents scripts doing things beyond the APIs I expose to them
  • Timeout / error handling so I can kill scripts which take too long or get stuck in loops (so people don't downrank my app for their script's fault).

I have looked over the likes of Rhino and Jython and I get the impression they would impose far too great an overhead for my purposes. I also suspect they might be hard to coral into the limited security model I have in mind (eg Rhino exposes all Java classes by default and this has to be hacked around).

What recommendations would people give?

Take a look at SL4A project . I'm not sure if it provides what you need, but at least it's a place where I would have started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM