11

Is it possible to run Spring Boot on an Android device?

Right now I am successfully running a web service on localhost using Spring Boot which I've got building in IntelliJ IDEA. I need to get the same web service code running on an Android device. Is it possible to build the web service app into a JAR file that I can get running on an Android phone? I have a Google Nexus 6P running Android Nougat. I've done some limited research, and have found an application called JBED. So far I haven't been able to get this working.

I've started from scratch and built the example JAR:

gs-spring-boot-0.1.0.jar

and hopefully I can find a way to run this JAR. I'm guessing it probably won't work so if anyone has a better idea that would be great!

Lou Morda
  • 5,078
  • 2
  • 44
  • 49
  • Anything is possible. Most likely it will be challenging though, as you're fighting the natural software design paradigm for the (Android mobile phone) platform. – ryanwebjackson Jun 04 '21 at 16:51

3 Answers3

4

You can use i-jetty to host servlet based apps in android. or embed i-jetty (replacing tomcat or netty) in your spring boot app

norok2
  • 25,683
  • 4
  • 73
  • 99
GiBi
  • 127
  • 3
2

Short answer is you're not gonna be able to directly run your spring boot application on your android phone. Spring boot is meant as a wrapper to quickly bootstrap Spring applications and is going to best serve you when building web based applications. As I see it you have two options.

  1. Deploy your jar on the cloud somewhere(ec2,digitalocean, heroku, cloud foundry, etc.) and just access your Spring MVC app from the android browser. If you have some really complex logic in your boot app that you don't think you can port to android, you can still deploy your boot app in the cloud, and create a really "dumb" front end android application that consumes all of it's data from the spring boot app running externally.
  2. Port you current spring boot application to a true Spring for Android project. http://projects.spring.io/spring-android/. The tools are out there to help you port it over all you have to do is put the work in.
mross1080
  • 144
  • 1
  • 7
0

There's an AnLinux app in play store that helps install a Linux distro inside termux.

I was able to install open jdk, spring cli and then run an spring boot project in that.

Here's a video I recorded demoing the same - https://m.youtube.com/watch?v=n9CY2wZPWJ0&t=1s