VOOZH about

URL: https://www.geeksforgeeks.org/android/steps-to-integrate-of-local-host-with-android-kotlin/

⇱ Steps to Integrate of Local Host with Android Kotlin - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Steps to Integrate of Local Host with Android Kotlin

Last Updated : 23 Jul, 2025

In this article, we will build an Android app using Kotlin that connects to a local host server. You will learn how to configure your development environment, set up a local host server on your machine, and make network requests from the Android app. By the end of this article, you’ll have a fully functional app that communicates with a local backend server, enabling you to test APIs and backend logic without deploying to a live environment.

Note: make sure the hosting server device and the client device must be on the same network and none of them should be the source of the network.

Step by Step Implementation of Integration of Local Host with Android Kotlin

Let us check Steps to Implementation of Integration of Local Host are mentioned below:

Step 1: Install Express and CORS

To set up a Node.js backend, install Express with npm install express to handle routing and server-side functionalities, and CORS with npm install cors to manage cross-origin requests. Express simplifies building web applications, while CORS allows your server to handle requests from different domains, essential for frontend-backend communication.

npm install express
npm install cors

Step 2: Implement the Code Below in your server.js or app.js

Step 3: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Note: Select Kotlin as the programming language.

Step 4: In the Android app manifest, add the Internet permission.

<uses-permission android:name = "android.permission.INTERNET"/>

Step 5: In the manifest, within the <application> element, add android:usesCleartextTraffic="true".

Step 6: Add the Retrofit dependency in build.gradle (Module: app).

// Retrofit Gson Converter: This dependency allows Retrofit to automatically convert JSON responses into Kotlin objects using Gson.
implementation("com.squareup.retrofit2:converter-gson:2.9.0")

// Retrofit Core Library: This is the core Retrofit library used for making HTTP requests in Android.
implementation("com.squareup.retrofit2:retrofit:2.9.0")

Step 7: Create a data class (Responses.kt) for defining the response that you get from the API.

// Json response we are getting
{response : "API call successful" }

Note: The variable name defined in the data class and the key of the JSON response must be the same in order to receive the response from the API.

Step 8: Create an API interface (ApiService.kt) in which you define your functions and methods of the API interface.

Step 9: Create an object file (RetrofitBuilder.kt) for building Retrofit to make API calls.

Step 10: To get your system's IPv4 address. Run below mentioned command inside your terminal.

ipconfig (For windows)
ifconfig (For mac)
👁 comand
OUTPUT

Step 11: Inside Android Studio, add the following XML code in your layout XML file.

Step 12: Now, add the following code inside your MainActivity.kt file.

Output of the Application:

👁 apicalls
API integrated app


Comment

Explore