Skip to content

Running Java Spring Boot on pure Android phone or virtual device

License

Notifications You must be signed in to change notification settings

higorvaz/Java-Spring-Boot-on-Android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 

Repository files navigation

Java-Spring-Boot-on-Android

Running Java Spring Boot on pure Android phone or virtual device

"Pratique a linguagem de programação e o framework mais utilizado por grandes corporações somente com seu Smartphone Android e sem necessidade de alterar configurações avançadas como "root" ou instalação de aplicativos suspeitos."

Screencast at YouTube Screencast at YouTube

.

What you'll build

You will build a classic “Hello World!” endpoint which any browser can connect to. You can even tell it your name, and it will respond in a more friendly way.

What you’ll need

  • An Android phone or an Android Virtual Device (AVD)
  • A command line Android app, I recommend Termux
  • A Java™ Development Kit (JDK)
  • Basic Linux command line knowledge 
  • Will and curiosity

Step 1: Start a new Spring Boot project

Use start.spring.io to create a “web” project. In the “Dependencies” dialog search for and add the “web” dependency as shown in the screenshot. Hit the “Generate” button, download the zip.

Locate the downloaded demo.zip file path.

Copy it to the home Termux folder

cd && cp /storage/emulated/0/Download/demo.zip demo.zip

Unzip it and go to the demo unzipped folder

unzip demo.zip && cd demo

Step 2: Check system requirements

Verify if you have Java installed on your system

java -version

If no, update your system and install it

apt update -y && apt upgrade -y && apt install openjdk-17-jdk

Step 3: Add your code

Remove the original file DemoApplication.java located at src/main/java/com/example/demo folder.

rm src/main/java/com/example/demo/DemoApplication.java

Now create and edit a new DemoApplication.java adding the code below

nano -l -A -S -m src/main/java/com/example/demo/DemoApplication.java

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        return String.format("Hello %s!", name);
    }
}

Save

CTRL + o

Exit

CTRL + x

Step 4: Try it

./mvnw spring-boot:run

It will take some seconds to compile and show the results like this:

Open your browser and in the address bar at the top enter https://localhost:8080/hello .

You should get a nice friendly response like this:

Charade ¯\_(ツ)_/¯  :

What is displayed if you add ?name=HigorVaz to the end of the URL?


 

This guide was made taking the official Spring Boot documentation:

https://spring.io/quickstart

.

About

Running Java Spring Boot on pure Android phone or virtual device

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published