Part of the ownCloud ecosystem is the Android client. Unfortunately, this part has some catching up to do, as it lacks certain obvious features such as downloading an entire folder, picture thumbnails and a way of searching for files. So in this post, I’m covering how to set up a build server for the ownCloud Android client.
Lately, I’ve been looking into ownCloud, an alternative to various cloud services such as Dropbox, Skydrive and Google Drive. Although it’s still very much in development and not at the same level as it’s competitors, I’m really impressed by the concept. Cloud storage is an amazing idea, but I always struggled with having your files stored at some random place I can’t actually get to or control. Because I can host ownCloud myself, it pretty much solves those problems.
1. Base installation
For the build server, I’m using a virtual machine to ensure a clean installation with as few problems as possible. You can choose to do the same or simply install everything on your host machine. Anyway, should you want to use a virtual as well, here are the specs I’m using:
- Oracle Virtual Box
- Windows 7 Professional
- 1GB Ram
- 25GB HDD
2. Install msysgit from https://code.google.com/p/msysgit/downloads/list.
Select ‘Run Git and included Unix tools from the Windows Command Prompt’, so we can simply run everything from the command line.
3. Install Java Development Kit (JDK) from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
4. Install Apache Ant from http://ant.apache.org/bindownload.cgi Download the zip archive and unpack to C:\apache-ant-1.9.2. Of course, the version number can deviate.
5. Add C:\apache-ant-1.9.2\bin to the PATH.
6. Install Android SDK from http://developer.android.com/sdk/index.html Unpack to C:\adt.
7. Add C:\adt\sdk\tools to PATH.
You should now be able to run 'git’, 'java’, 'ant’ and 'android’ from the command prompt.
8. Install Android API 17 or higher.
We now have all required software to build an .apk file. It’s time to download the latest sources from github.
9. Clone the latest sources from GitHub using the command line:
git clone --recursive https://github.com/owncloud/android.git
Optionally, you can add the ’–recursive’ flag, which already downloads submodules. However, the next step will also take care of this.
This creates a directory called 'android’.
10. Run setup_env.bat from the android directory. This sets up everything android-related.
11. Create a key for signing the apk. I’m putting this in a bat file called '0 - generate-key.bat’. You only need to run this once, as long as you don’t delete the resulting key file or lose the password.
"C:\Program Files\Java\jdk1.7.0_25\bin\keytool" -genkey -v -keystore owncloud-custom.keystore -alias cloud -keyalg RSA -keysize 2048 -validity 10000
The path to the jdk may vary depending on the version you downloaded.
Fill in all requested data. Use the same password for both the keystore and the signing key. Save the password somewhere.
Generating the apk
12. Update sources. '1 - get-latest.bat’. This ensures you have the latest resources from GitHub, especially useful when running a build in a couple of days or weeks.
cd android git pull git submodule foreach git pull
13. Build. '2 - build.bat’. Compiles the source files into an unsigned apk.
ant -f android\build.xml clean release -Dsdk.dir="C:\adt\sdk"
Note: Possibly, you will see a Java error here, along the lines of 'Unable to locate tools.jar. Expected to find it in C:...’. See this for a solution.
14. Sign. '3 - sign.bat’. Signing enables verification of the application’s origin. Simply put, it enables installing the app without developer mode.
"C:\Program Files\Java\jdk1.7.0_25\bin\jarsigner" -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore owncloud-custom.keystore ownCloudAndroid\bin\ownCloud-release-unsigned.apk cloud
15. Align. '4 - align.bat’. Arranges the bytes of the app in such a way that it uses less RAM.
zipalign -v 4 android\bin\ownCloud-release-unsigned.apk owncloud.apk
Now that all scripts are in place, we can run them each time we want to roll a new release. Note that you can skip generate-key, as long as the keystore is still available.
16. Now you have a signed and aligned apk, just transfer it to your Android device via e.g. usb, bluetooth or an ftp site.