Develop a VPN App in Java using Android Studio

Gayan Kuruppu
4 min readSep 23, 2019
Android VPN Client (Source)

Pretty much if you are working on building an Android VPN app, OpenVPN comes out as an option. Since OpenVPN has a lot of community support, you can easily build a VPN client for any platform.

Go to Github repository https://github.com/gayankuruppu/android-vpn-client-ics-openvpn

For Android, it is really hard to find an article describing all the things that need in VPN development. So I have created to an app in Java, using Android Studio.

In this, we will be working on the latest version of the Android Studio, and Gradle. I used Android Studio 3.5, and for Gradle 5.6.1.

Dark Mode

The app is migrated to AndroidX and supports 64 Bit. It can calculate the daily usage of data, the connected time, check connection speed, change the interface into night-mode, add multiple servers, remote config the app, added visual effects to the transitions, and integrated Lottie.

You can get the app from Google Play Store, UptoDown, and Amazon

  1. httphttps://play.google.com/store/apps/details?id=com.buzz.vpn
  2. https://buzz-vpn-fast-free-unlimited-secure-vpn-proxy.en.uptodown.com/android
  3. https://www.amazon.com/Buzz-VPN-Free-Pop-up-Ads/dp/B07T3X677T

The servers may not work and give you back a notification if tried to connect to a server. Because the servers are removed, and you have to add your servers to the app.

1. Clone the project

To clone the project, follow the steps.

Step 1: Select Git from Check out project from Version Control

Step 2: Paste the link of the repository in URL and choose a folder in Directory to clone the repository and select Clone button

Step 3: Click Yes in the Checkout From Version Control

Step 4: Build the project using the latest Gradle version

Step 5: After finish, the Building project. Change the following lines to add new servers

Now you can run the project on a simulator or the device. But still, the app will not connect to servers, because we haven’t configured it.

2. Configure appdetails.json

{
"ads":"true",
"update":[{
"version":"2.8.1600",
"title":"This app is now Open Source",
"description":"The App is available at github.com/gayankuruppu/android-vpn-client-ics-openvpn",
"size":"https://git.io/JeY69"
}],
"blocked":[
{"id":0, "app":"com.android.game"},
{"id":1, "app":"com.utorrent.client"},
{"id":2, "app":"com.torrent.client"},
{"id":3, "app":"com.tor.client"},
{"id":4, "app":"com.insta.client"},
{"id":5, "app":"com.facebook.client"},
{"id":6, "app":"com.get.client"}
],
"free":[
{"id":0, "file":0, "city":"Essen","country":"Germany","image":"germany","ip":"51.68.191.75","active":"true","signal":"a"},
{"id":1, "file":0, "city":"Hamburg","country":"Germany","image":"germany","ip":"51.68.191.75","active":"true","signal":"b"},
{"id":2, "file":1, "city":"Los Angeles CA","country":"United States","image":"unitedstates","ip":"205.185.119.100","active":"true","signal":"c"}
]
}

The appdetails.json file has four main parts.

  1. The value ads is a boolean value, you can choose true or false. If the value is true, the app will show ads when the session starts. Otherwise, ads will not show if the value is false.
  2. The array update has three values. version is a String value which is the latest version of the app. When the session starts the app check if the version value is equal to the version of the app. If the values do not match with each other the Update View will show. The values title, description, and size are the values display in the Update View.
  3. The array blocked has JSON objects with values id and package name. You can add apps such as Torrent to avoid the peer to peer file sharing which often misuse by downloading digital media.
  4. The array free has values of the server names. The value city displays the server name and the value image is the name of the flag. The value signal is the value of the strength of the signal.

Change the JSON values and upload into your server or host it in the forked repository (https://raw.githubusercontent.com/gayankuruppu/gayankuruppu.github.io/source-json/appdetails.json) and add the link of the JSON file in the WelcomeActivity.java file https://github.com/gayankuruppu/android-vpn-client-ics-openvpn/blob/c35b88b40a8ba6aa382ca7324981511f4c6e886d/app/src/main/java/com/buzz/vpn/WelcomeActivity.java#L59

3. Configure filedetails.json

{
"ovpn_file":[
{"id":0,"file":"client
dev tun
proto udp
...
d4ec4105a39c814bd980c9c0e0b8efb4
-----END OpenVPN Static key V1-----
</tls-auth>"},
{"id":1,"file":""}]
}

The filedetails.json file stores the OpenVPN file string value. Copy the text in the OVPN file and paste it in the JSON String (https://raw.githubusercontent.com/gayankuruppu/gayankuruppu.github.io/source-json/filedetails.json) and add the link address in the WelcomeActivity.java https://github.com/gayankuruppu/android-vpn-client-ics-openvpn/blob/c35b88b40a8ba6aa382ca7324981511f4c6e886d/app/src/main/java/com/buzz/vpn/WelcomeActivity.java#L60

4. Run the app

That is all. Now to can change the app UI and deploy the app. Remove the Google Services JSON file before deploying (https://github.com/gayankuruppu/android-vpn-client-ics-openvpn/blob/master/app/google-services.json)

Github https://github.com/gayankuruppu/android-vpn-client-ics-openvpn

If you enjoyed this story, please click 👏 and share to help others find it!

--

--