Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Frege programs on Android?

I'm interested in programming for Android in functional languages, preferably close to Haskell. Frege seems to be a good choice. I found that somebody has already done such a proof-of-concept application, but I couldn't find its sources or anything similar.

So my question is, how to run Frege programs on Android, how difficult it is and what are eventual obstacles?

like image 477
Petr Avatar asked Jun 20 '13 19:06

Petr


2 Answers

The main obstacle I see is that it is currently not possible to compile a frege source to a java class that implements some interface or extends another class.

Instead, the java class generated from a frege module is just a namespace for static methods and other stuff you defined.

Hence, to make a more than trivial Android project, it'll not be enough to call java from frege, which is quite easy, but also to call frege from java. In other words, you'll need full *inter*operability in the literal sense.

Of course, it is possible to do, but it must be said that the code generation was not exactly designed for easy use from java.

I have not done an Android project yet, hence I am not sure just how much glue code one would need.

One final warning: the previous work by Gabriel Riba was done with an earlier version of the compiler. There's even a link to a frege distribution that supports JDK6 - please don't use that one, it's not compatible with more recent versions.

If you're nevertheless willing to take it on, you'll get every possible support through the google group mentioned above. It'd be too great if someone made and documented some "canonical" way to achieve this.

like image 64
Ingo Avatar answered Oct 03 '22 13:10

Ingo


I'm not familiar with frege, and I haven't tried to use scala or other JVM languages on Android.

That being said, if I were to try something like that, these are the steps I would likely take to try and figure out how to get it to work.

  1. Build a simple command line based HelloWorld type application in frege, that can be run with, e.g. java -jar HelloWorld.jar HelloWorld

  2. Run dx on HelloWorld.jar, and then try to get the example working on an android device from adb shell, using dalvikvm. i.e. dalvikvm -cp blah.dex HelloWorld

  3. Figure out how to reference/use classes from the android.jar provided by the Android sdk in frege

  4. Build a simple proof of concept Activity class in frege, and manually build a classes.dex file from it

  5. Build a similar proof of concept application in java and use the existing android tools to build an apk

  6. Replace classes.dex in the apk, resign the apk, and see if it works

  7. If you get that much working, then from there, you can work on a better build story for frege, using aapt to compile resources and eventually build a full apk "from scratch".

like image 21
JesusFreke Avatar answered Oct 03 '22 15:10

JesusFreke