Running Play on Android

744 views
Skip to first unread message

Nic Pottier

unread,
Aug 16, 2011, 12:00:01 PM8/16/11
to play-fr...@googlegroups.com
Crazy idea, I know, but we are doing a project that is going to involve running a webserver on an Android phone.

I know Jetty runs quite well on recent hardware, but I'd like to start with a decent framework and Play is my top candidate.  Anybody know if anybody has pursued this path?  Play running it's owner server actually seems like it could make it easier, but obviously there are a lot of other issues at play. (hah!)

Thanks,

-Nic

grandfatha

unread,
Aug 16, 2011, 3:56:08 PM8/16/11
to play-framework
I have neverr done any mobile development, is the whole JDK supported
on an Android device?


There is a Server class that has a main method from which you can see
how to bootstrap a Play instance. Another idea is to use a war file as
you already have Jetty running? But all of Plays dependencies are
gonna take some disk space...

Nic Pottier

unread,
Aug 17, 2011, 3:03:46 AM8/17/11
to play-fr...@googlegroups.com
The Android SDK is pretty complete, most things run without modifications though there are exceptions.

Absolute code size isn't a big deal, after all people download games that are absolutely huge.  Resident memory is another matter though.

I'll download things and see how feasible it is, just wanted to check whether anybody had given it a go yet.

Thanks,

-Nic

Kiran Rao

unread,
Sep 5, 2012, 7:36:33 AM9/5/12
to play-fr...@googlegroups.com
Hi Nic,

Did you get around to experimenting with this? Were you able to get play! framework to run on Android?

I know this is a very unusual approach - but not totally useless. I am developing a REST API and an Android app using that API. Now, it would be so easy to demo the application if both the REST API and the client app both run on an Android phone.

From feasibility perspective - my worry is about custom classloaders. If Play! framework uses it to run an app, then we are pretty much out of luck. Else, we can warp the "bootstrap" code (play.server.Server) in an Android Service and proceed from there.

So, back to the question - did you get this running?

Kiran Rao

unread,
Sep 5, 2012, 9:06:31 AM9/5/12
to play-fr...@googlegroups.com
To answer my own question, a cursory glance through the source code of play.server.Server and associated Java files (for play 1.2.4) shows that Play! uses some features of Java not supported by the Android platform. I came across the following API's being used, but there may be more:
  • JMX (java.lang.management.*)
  • Intrumentation (java.lang.instrumentation.*)
I do not know if these are "optional" features that can be stripped off or not. Looking for an authoritative comment from someone on the play! team.

Guillaume Bort

unread,
Sep 5, 2012, 9:21:18 AM9/5/12
to play-fr...@googlegroups.com
Play 2.0 in production should work fine I fine.
> --
> You received this message because you are subscribed to the Google Groups
> "play-framework" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/play-framework/-/nxWzqJHTrscJ.
>
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to
> play-framewor...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/play-framework?hl=en.



--
Guillaume Bort, http://guillaume.bort.fr

Kiran Rao

unread,
Sep 5, 2012, 9:34:04 AM9/5/12
to play-fr...@googlegroups.com
Hi Guillame,

Thanks for the response. Just to clarify your comment, Are you saying that a play 2.0 app with the mode set to prod should run fine on Android (even without the JMX and instrumentation pieces)?

If so, I can try wrapping the play.server.Server class in an Android Service and find a way to pass the args [] as android Intents.

Guillaume Bort

unread,
Sep 5, 2012, 10:26:01 AM9/5/12
to play-fr...@googlegroups.com
I think so because the production mode of Play 2.0 use nothing special
(no custom classloader, no instrumentation). Actually the whole dev
mode dependencies are not required anymore to run a Play 2.0
application in production mode.

Now, I can't assure that it is possible to run it on Android but at
least it should be ways simpler than for Play 1.x
> https://groups.google.com/d/msg/play-framework/-/od_bUJ2nZskJ.

Kiran Rao

unread,
Sep 5, 2012, 10:28:19 AM9/5/12
to play-fr...@googlegroups.com
Thanks Guillame! I will experiment with this a little more.

Kiran Rao

unread,
Sep 7, 2012, 10:24:23 AM9/7/12
to play-fr...@googlegroups.com
Hi Guillame,

I see the NettyServer implementation references JMX (which is not available on Java).
I wish to run this on Android, is it is safe to comment out the JMX portion? Is the PID file used elsewhere in the framework?

/**
   * creates a NettyServer based on the application represented by applicationPath
   * @param applicationPath path to application
   */
  def createServer(applicationPath: File): Option[NettyServer] = {
    // Manage RUNNING_PID file
    java.lang.management.ManagementFactory.getRuntimeMXBean.getName.split('@').headOption.map { pid =>
      val pidFile = Option(System.getProperty("pidfile.path")).map(new File(_)).getOrElse(new File(applicationPath.getAbsolutePath, "RUNNING_PID"))

      // The Logger is not initialized yet, we print the Process ID on STDOUT
      println("Play server process ID is " + pid)

      if (pidFile.getAbsolutePath != "/dev/null") {
        if (pidFile.exists) {
          println("This application is already running (Or delete "+ pidFile.getAbsolutePath +" file).")
          System.exit(-1)
        }

        new FileOutputStream(pidFile).write(pid.getBytes)
        Runtime.getRuntime.addShutdownHook(new Thread {
          override def run {
            pidFile.delete()
          }
        })
      }
    }

    try {
      val server = new NettyServer(
        new StaticApplication(applicationPath),
        Option(System.getProperty("http.port")).map(Integer.parseInt(_)).getOrElse(9000),
        Option(System.getProperty("http.address")).getOrElse("0.0.0.0"))
       
      Runtime.getRuntime.addShutdownHook(new Thread {
        override def run {
          server.stop()
        }
      })
     
      Some(server)
    } catch {
      case e => {
        println("Oops, cannot start the server.")
        e.printStackTrace()
        None
      }
    }

  }

jpro technologies AG

unread,
Sep 29, 2016, 5:18:45 PM9/29/16
to Play Framework
Hi Kiran,

do you reached your goal on running play 2.0 on android?

Best,
Tobi

Kiran Rao

unread,
Oct 2, 2016, 8:53:20 AM10/2/16
to Play Framework
Hi Tobi,

No, I abandoned the experiment and went with Restlet framework instead. I like Play! and it excels at being a server-side web framework but it was not suitable for my requirements at the time.
Reply all
Reply to author
Forward
0 new messages