How to set up a mobile build server: step 1

  1. Introduction
  2. Server-side and client-side: (Optional) Create and configure an user on the build server
  3. Server-side: Install and configure the Android SDK
  4. Server-side: Install and configure cordova/ionic
  5. Client-side: Automate the build process

Server-side and client-side: (Optional) Create and configure an user on the build server

In this part, we will create a new user and configure ssh access. It’s an optional part because you can use an existing user.
I chose to separate the user because I think an user on a server must create for only one thing.
On top of that, as I said in the introduction, this method can be used for a C, LaTeX (or anything else) build server. An user for each build method is better in this case.

The user will be called android-sdk.

It’s the only part of this tutorial you need root access to create the user

Server-side: Create the user

Connect to the server and create a new user:

adduser android-sdk

You’ll be prompted for some informations such as a name, full name, and a password.

Client-side: create a ssh key and add it to the server

To avoid having to type the password each time we push, we create a ssh key and add it to the android-sdk’s authorized keys.

ssh-keygen -t rsa -f ~/.ssh/android-sdk
ssh-copy-id -i ~/.ssh/android-sdk android-sdk@[your-server]
Replace [your-server] by your server ip/alias/domain name. If you’re on Mac OS X, install ssh-copy-id with brew (brew install ssh-copy-id).
It’s recommended to have different ssh keys for each ssh user that is for github.com, bitbucket.com or other users on your server.

Client-side: add a rule in the ssh config

If you followed the previous command, you must add a rule in the ~/.ssh/config file to match the appropriate ssh key file.
Open with your favorite text editor (vim of course :D) and add these lines

Host build-server
Hostname [your-server-adress/ip/alias]
IdentityFile ~/.ssh/android-sdk
User android-sdk
See this excellent tutorial for more informations about the ssh config file. Don’t forget to change the user if you’re using another user. Same for the ssh key file.

The host will be used when you’ll clone the repository. You will use somethink like

git clone android-sdk@build-server:~/my_amazing_project.git

Scripts

As promised, I give you scripts to automate the configuration. There’re two scripts: one for the server and one on the client machine.

Server

We only need to create the user. I only add a variable to let you choose your user name.

## Change it if you want another username.
## Don't forget to change in the client script too.
USERNAME = android-sdk

## DON'T EDIT THESE FOLLOWING LINES
adduser $USERNAME
##

Client

We need to create a ssh key, add the ssh key to the server and modify the ssh config file. If you changed the username in the script server.

##### Change it if you want another username.
## Don't forget to change in the server script too.
## [default = android-sdk]
USERNAME = android-sdk

## Your server IP adress or alias
HOSTNAME = danny-willems.be

## The host name you want to use when you'll clone
## [default = build-server]
HOST = build-server

## SSH key name
## [default = android-sdk]
SSH_KEY_NAME = android-sdk

## DON'T EDIT THESE FOLLOWING LINES
## Create SSH keys
ssh-keygen -t rsa -f ~/.ssh/$SSH_KEY_NAME

## Copy to the server
ssh-copy-id -i ~/.ssh/$SSH_KEY_NAME $USERNAME@$HOSTNAME

## Modify the ssh config file
echo 'Host $HOSTn Hostname $HOSTNAMEn IdentityFile ~/.ssh/$SSH_KEY_NAMEn User $USERNAME' >> ~/.ssh/config

And now ?

OK, user configured. Now, let’s download and install the Android SDK in our new user environment.

Go to the second part

How to set up a mobile build server

Why a mobile build server ?

To develop mobile applications whether for Android, iOS, Tizen or Windows Phone, we need to use the SDK for the appropriate platform. The size of these SDK is more than 1Go for the basics and it can reach around 10-15Go if we download sdk for different versions.

Frequently, in a company, several developers works on a mobile project and it’s very annoying to download the SDK on each workstation. An other case it’s when you work with different OS or different computers: you need to download the SDK multiple times.

Centralized the SDK

A solution is to install the SDK only once on a server which will compile and build the archive for the platform. A mobile project will be in a git repository which will be on the server. The project will be compiled and the archive will be sent to the developer. It will follow this simple process:

  1. Server-side: Create a git repository on the server
  2. Client-side: Clone the repository, work on it, commit and push.
  3. Client-side: Execute a script which will build the project on the server and copy locally the remote archive (apk, ipa, etc).

I will present this solution for the Android SDK which is the easiest to put in place. More specifically the server will be a solution for decentralized cordova/ionic build system.

No graphical interface is needed. This process could be used on an old server, a raspberry pi or anything else. Just need a terminal.

Wait… Other solutions like a docker container or continuous integration system exist. What’s the difference ?

There’re some docker images like this which does the job. Even if I like docker and use it, we must download the image, run it and it takes some place and resources (not a lot) and we don’t have always these resources.

Generally, continuous integration system provide more than we need. And when we want to modify a behavior, we wast time to learn how it’s working. Also some continuous integration system needs some specific resources requirement.

An other point is this method doesn’t require root privileges (for Android SDK): it could be used independantly by a user.

Last this method works on Mac OS X server and only the build script (see below) must be changed. The Mac OS X script will also be given.

No root privileges required, no need a lot of resources, easy to install and to use, no graphical interface needed.
This tutorial is tested and developed for a ssh server running on Linux with git, wget and npm installed (cordova/ionic).

Now, let’s go !

This “How-To” tutorial will be separated into 3 parts for the server configuration and a script for the client.

  1. Server-side and client-side: (Optional) Create and configure an user on the build server
  2. Server-side: Install and configure the Android SDK
  3. Server-side: Install and configure cordova/ionic
  4. Client-side: Automate the build process

At the end of each part, a script to automate everything will be given.

Important: we can transform the server for another type of compilation such as C, LaTeX, etc with the same idea. We only have to change the username and the client build script.

Go to the first part

GSMath

GSMath: a math hybrid library.

In the same idea than GSLib GSMath is a library, available in multiple languages, keeping the same structure and the same functions. GSMath provides functions to do linear algebra (matrix), differential analysis, basic algebra, trigonometry,…

What’s an hybrid library and why ?

I think programming languages must be seen as a tool, not as a “raw material”.

I don’t say every programming languages is equivalent in the sense there’re no needs to compare them. There’re better programming languages than other, and it depends on what you have to do. There’re also different theoric aspects of programming languages which matters a lot. For example, you’ve to be foolish to code a JQuery like or a web render in brainf***. As a tool, there’re better tools than other (but it’s not the subject of this article, maybe later).

I think a programming language must be seen as a way to communicate with your computer as you want: the compiler or interpreter is there to translate to your machine. So, why do we have to learn a new standard library when we learn a new programming language ? Why do we have to talk differently to each interpreters and compilators ?
It’s not very productive and we don’t often remember basic functions because we have to switch between different syntaxes.

You shouldn’t be afraid about the syntax and the semantic to learn a new programming language or when you work with several languages.

For these reasons, I began to write a library I called GSMath. I say it’s an hybrid library because you can use it in the programming language you want with the same namespace and the same algorithms for the implementation. The last point is I think important because when we want to learn a new programming language, it’s a good way to learn to study how standards libraries are implemented.

GSMath isn’t always the fastest and the more efficient implementations of math libraries.

GSLib

GSLib: an hybrid library.

When we learn a new programming language, we must read a lot of documentation to know which basic functions do what we want such as create a linked list, a tree, a graph, …
GSLib is a library, written in multiple languages, keeping the same structure and providing the same functions and data structures for all languages, which let you easily switch to a new language.

What’s an hybrid library and why ?

I think programming languages must be seen as a tool, not as a “raw material”.

I don’t say every programming languages is equivalent in the sense there’re no needs to compare them. There’re better programming languages than other, and it depends on what you have to do. There’re also different theoric aspects of programming languages which matters a lot. For example, you’ve to be foolish to code a JQuery like or a web render in brainf***. As a tool, there’re better tools than other (but it’s not the subject of this article, maybe later).

I think a programming language must be seen as a way to communicate with your computer as you want: the compiler or interpreter is there to translate to your machine. So, why do we have to learn a new standard library when we learn a new programming language ? Why do we have to talk differently to each interpreters and compilators ?
It’s not very productive and we don’t often remember basic functions because we have to switch between different syntaxes.

You shouldn’t be afraid about the syntax and the semantic to learn a new programming language or when you work with several languages.

For these reasons, I began to write a library I called GSLib. I say it’s an hybrid library because you can use it in the programming language you want with the same namespace and the same algorithms for the implementation. The last point is I think important because when we want to learn a new programming language, it’s a good way to learn to study how standards libraries are implemented.

GSLib isn’t always the fastest and the more efficient implementations of stardard libraries. For example, if you’re on an embedded system, use GLib is a better library because asm code is used to optimize on the platform.
Due to a bad manipulation, GSLib must be rewritten. A documentation and implementation in pseudo-code will be soon available.