TL;DR: This is a series of posts where I'll walk you through the process of how I created an Android application from scratch. Both the app and backend source codes are on Github, as well as the data.
As an adult, I've never been a big video game player. I completely lost interest at some point and only recently bought a PS4 started playing again. My go-to game is usually FIFA, since I'm a huge soccer fan and enjoy playing quick matches with low commitment, instead of having to spend hours playing through a campaign. This way I know it's harder for me to get super hooked, so I can still have a life and keep sanity :)
I wanted to create an Android game, but it's pretty hard to do that alone without the help of a designer or a bigger team to create assets. Also the other day I was remembering how I really enjoyed playing Elifoot as a teenager. That was an old Windows desktop game where you managed a soccer team (instead of playing the game) and had to build a strong group of players in order to move up through the divisions. It is the precursor of games like Football Manager.
Here's what you'd look at while your team is playing. Quite different from today's 3D soccer games like FIFA and Pro Evolution Soccer.
I wanted to recreate this memorable experience for Android in 2015 with a modern design, keeping the original game experience that was so addictive, but in a way that I could leverage up to date information like today's teams, players, ratings, etc. So I digged into how I could consume the FIFA Ultimate Team data and feed it into this game. There are a couple websites that already do it by scraping data, like FutHead for example, but I figured that would be a lot of work. I also found a few projects on Github that already do similar work, especially this one which already had links to the CDN where the data could be extracted from. Still it would be a lot of work to download everything and categorize/catalog, so I looked a bit further and found the FUT (FIFA Ultimate Team) Database on the EA Sports website, which seems to have all the data I need. I opened Chrome DevTools to check out what was going on and there it was! All the data I needed structured in a nice JSON API:
So it turns out that EA Sports seems to provide a neat public JSON API with all the available data. Here's how you could grab the details on Cristiano Ronaldo, for example: https://www.easports.com/fifa/ultimate-team/api/fut/item?jsonParamObject=%7B%22baseid%22:%2220801%22%7D
This is pretty much all I needed to get started. So combining the information I found on Github with the public JSON API, I was able to extract all the players, clubs, nations and leagues into a Postgres database. I won't get too much into the details of how this was done but, if you're curious, here you can see the rake tasks that reads the players JSON into a Rails ActiveRecord Player model and saves it into the database.
So here's the first key concept when you're going to create an Android application:
Your Application needs to consume its data from somewhere, usually an API or a web service.
You have pretty much 3 options here:
- You could simply embed all the data you need into your app package (.apk file). However that quickly grows out of control, as you'd have a 500Mb+ file for users to download in order to install your app. Also, what if you need to add more players or update their information? Now you need an app update in order to do it. On the other hand, the nice thing about this is that your app doesn't require internet in order to work, everything you need is already available in the device! In fact I considered that option, but after looking at how many players there were (over 16 thousand) and all the images associated with each player (headshots), it quicky became clear that it wasn't the best option.
- Another simple option would be to consume the EA Sports FUT JSON API directly. At first that doesn't sound like a bad idea, but what if they have an outage and stay offline for hours or days? What if their JSON format changes or they simply decide to block you? All of a sudden your app stops working and there's nothing you can do about it.
In order to provide a solid service, you need to own your data.
So here's our goal: create our own service to consume the data. This is definitely more work, as you have to extract all the information from the FUT API, structure it and store yourself. However, this gives you a lot more control and confidence to know exactly if and how your app is working. If your service goes down, you have the responsibility to fix it and take it back up. You have complete control over your data format and how it is served. This is the best and recommended approach for any service that needs a minimum level of reliability.
It's not in the scope of this article to cover the service setup, however the code is all on Github, so please feel free to take a look around and see how things work. Ultimately, our goal is to provide our own JSON API that the Android application is gonna consume. For that reason, we need to deploy our service somewhere where the app can access it, that is, you need to host it somewhere publicly accessible. For this demo, we're gonna host it on Heroku, which provides a free tier that is great for development and supports many different frameworks, including Ruby on Rails, which is the one we're using. Here's where we'll consume our data from.
This is the end of the Part I of this series. Next up we're gonna jump into the actual Android app code. Stay tuned!
… (edit) aaand here is Part II.