B07554b05ba6bf78ffed784fef5c496d
May 17, 2013

The Android SDK includes a flavour of JUnit that supports unit tests and instrumentation tests. This is sufficient if you are coding alone, but working in teams is a different matter. If you want to maintain a healthy master branch of your project whilst working in a fast paced and agile development process, you need tools that automate your application builds and test each change that is introduced in the project.

We rely on Travis CI to build and test web applications. Hence, we wanted to harness our current CI service for Android applications as well.

After a quick web search, we found this great blog post that helped us to make some configuration experiments with Maven. This was a nice starting point, but we felt some details were left apart, specially if you have no experience with Maven.

Therefore, we prepared this post as a step-by-step guide to get you started quickly with Maven and explain some changes to the Android application structure.

Requirements

Basically, you need to do 3 things:

  1. Change the structure of your Android Project.
  2. The building tools (Maven, Android Maven Plugin, Android SDK).
  3. Configure a 'travis.yml' file to make it work on Travis CI.

Step 1: Application structure

You have to change the directory structure of your Android application to comply with the structure shown below.

 Project-parent-folder:
   -Android-Application-folder
      -pom.xml
   -Android-Tests-folder
      -pom.xml
   -Android-library-project-folder
      -pom.xml
   -pom.xml
NOTES:
  • We assume you are using the Eclipse IDE.
  • If you already have the project in your Eclipse Workspace, you will need to delete it from your workspace and re-import it again (after you change the structure).

Step 2: MAVEN

Download Maven and extract the distribution archive to the directory in which you want to install Maven (e.g. apache-maven-3.0.5-bin.tar.gz).

Supossing you extracted the archive on your $HOME directory, then run on your terminal:

export M2_HOME=$HOME/apache-maven-3.0.5
export M2=$M2_HOME/bin
export PATH=$PATH:$M2
source ~/.bashrc

To verify that it is correctly installed:

mvn --version

Step 3: Eclipse Maven Android Plugin

You have to install a plugin to make the Android project work with Maven within Eclipse.

In Eclipse, go to:

"Help" > "Eclipse Marketplace"

If you are using Eclipse ADT or do not have the Eclipse Marketplace, install it from:

"Help" > "Install new Software" > "Switch to the Juno Repository" >
"General Purpose Tools" > "Marketplace Client"
Once in Eclipse MarketPlace:
  1. Search for: android m2e
  2. Install Android Configurator for M2E

Step 4: Eclipse Maven Android Project

To make Eclipse detect the project dependencies, you have to convert the Android and dependent Android Library projects to Maven:

  1. Right click on each project:
    • "Maven" > "Convert to Maven project"
  2. Right click on your Android project,
    • "Maven" > "Update Project"
    • Select the related projects and accept the changes.

This should get rid of any Eclipse error about some dependencies not found.

Also, you have to configure the 'pom.xml' files for each project. You can adapt these samples according to your project:

Step 5: Install Maven Android SDK Deployer

If you want to avoid the pain of configuring the Android SDKs in your local Maven repositories, this tool is a must.

Once you run this on your terminal, you will have all the Android SDK available as Maven dependencies.

git clone https://github.com/mosabua/maven-android-sdk-deployer.git
cd android-sdk-deployer
mvn install

Step 6: Install External Android Library Projects

If you are using any Android library project, you have to perform some additional steps:

  1. Compress the "library" folder of each library project and change the extension of the file to '.apklib'
  2. The .apklib files should be put in your Application 'libs' folder (e.g. AndroidProject/libs)
  3. Install each library on your local maven repository, as follows:

Run on your terminal, from your Android Application Project's root folder:

mvn install:install-file \
-Dfile=libs/your-library-file-1.apklib \
-DgroupId=com.your-library-package \
-DartifactId=your-library-artifact-id \
-Dversion=1 \
-Dpackaging=apklib

Step 7: Installing and deploying the application

These commands are for building the application and deploying to a device.

mvn clean install
mvn android:deploy

Step 8: Running Tests

On the Emulator:

mvn clean install -Pintegration-tests -Dandroid.device=your_emulator_name

on the Device:

mvn clean install -Pintegration-tests -Dandroid.device=usb

Step 9: Travis CI configuration

If everything works as it should in your local environment, then, all you need is to add a '.travis.yml' file to your application.

This is an example of the configuration we are using:

language: java
jdk: oraclejdk7
env:
 matrix:
   # android-16 is always included
   - ANDROID_SDKS=sysimg-16           ANDROID_TARGET=android-16  ANDROID_ABI=armeabi-v7a
   - ANDROID_SDKS=android-17,sysimg-17 ANDROID_TARGET=android-17  ANDROID_ABI=armeabi-v7a
before_install:
  # Install base Android SDK
  - sudo apt-get update -qq
  - if [ `uname -m` = x86_64 ]; then sudo apt-get install -qq --force-yes libgd2-xpm ia32-libs ia32-libs-multiarch > /dev/null; fi
  - wget http://dl.google.com/android/android-sdk_r21.1-linux.tgz
  - tar xzf android-sdk_r21.1-linux.tgz
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools

  # Install required components.
  # For a full list, run `android list sdk -a --extended`
  # Note that sysimg-16 downloads the ARM, x86 and MIPS images (we should optimize this).
  # Other relevant API's:
  #  addon-google_apis-google-16
  - android update sdk --filter platform-tools,android-16,extra-android-support,66,$ANDROID_SDKS --no-ui --force > /dev/null

  # Create and start emulator
  - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
  - emulator -avd test -no-skin -no-audio -no-window &

before_script:
  - chmod +x wait_for_emulator
  - ./wait_for_emulator

script: mvn install -Pintegration-tests -Dandroid.device=test

Also, note that we use the 'wait-for-emulator' script:

#!/bin/bash

bootanim=""
failcounter=0
until [[ "$bootanim" =~ "stopped" ]]; do
   bootanim=`adb -e shell getprop init.svc.bootanim 2>&1`
   echo "$bootanim"
   if [[ "$bootanim" =~ "not found" ]]; then
      let "failcounter += 1"
      if [[ $failcounter -gt 3 ]]; then
        echo "Failed to start emulator"
        exit 1
      fi
   fi
   sleep 1
done
echo "Done"

Both the Travis configuration file and Wait-for-emulator script were adapted from this Maven Android Example.

Finally

Push some changes to your Github repository (you need to have the Travis hook activated) and you should see that Travis builds and tests your Android application. Nice!

References

Check out MagmaConf, our very own international conference for Ruby specialists, coming soon in Mexico!

9d2d73612dcc5c42fa0ae4540002a77c
May 10, 2013

A couple of days ago I got up in the morning and, as usual, my laptop was on, I sat comfortably in front of my computer and headed to the one I visit first, Google Reader, but:

image alt

That box appeared over my precious feeds, my dismay was great when I received the bitter news from the hands of Google, the company I trust my personal information, my digital life. That menacing box marked "Google Reader will not be available after July 1, 2013" and a simple blue button with no other choice but "OK", I clicked the button and the box disappeared, but that feeling of discomfort and uncertainty did not.

Back in 2005

Doing some research, it didn't take long to learn from Google's official blog, that as part of a Second Spring Cleaning, Google Reader (among other products) will be gone by the first of July this year.

image alt

It is a rare feeling, like being kicked out of your own house, where you spend a lot of time, and you have grown accustomed to, I had started using Google Reader shortly after its launch in 2005, before that I used another service called Rojo, which offered functionality comparable to Google Reader. At that time Rojo was the best (in my humble opinion) way to read feeds in 2006. But when the Google app hit the market , of course I had to try it. I loved it and I stayed with it for more than six years, watching it evolve into the product it became to be. But in recent months, it seemed lacking in features... maybe that was a sign of what laid ahead, I did not see it coming.

Alternatives

So I started reviewing my options to continue reading my feeds. I thought of finding a desktop application, but none of the ones I've tried ever convinced me. The idea of having all my feeds in a single place, available and synced to use in all of my devices, was something I was never ready to give up. Many sites have listed alternative to Google Reader, but the one from lifehacker stands over the rest.

Abandon Ship

So, I started packing up and getting ready to move one. The first step before leaving Google Reader is taking with you your highly valued feed list, with that would be enough, but if you are worried about your followers, people you follow, favorites, among other things , Google offers a service that seems effective, this is called Google Takeout, an gets your "luggage" ready for you. It can be found withing your Reader settings, in the import tab / export.

image alt

Google Takeout generates a zip file with the selected services, in this scenario with the Google Reader files, among the files you can find in the package we have:

  • Followers
  • Followed
  • Liked
  • Notes
  • Shared
  • Shared by Followers
  • Starred
  • Subscriptions

All in standard formats such as JSON and XML. And well, with suitcases in hand, it's time to choose a new home.

Feedly

Many authors agree, and rightly so, that Feedly is one of the best, or the best alternative to Reader in the current app market, but in my opinion it is a little overloaded with eye candy, but it works well enough. The navigation is through shortcuts like Reader, and it has different layouts for different content you may have in your feeds.

image alt

Currently, Feedly lets you import all your feeds from Google Reader, you just have to grant permission to a third-party application, it is not necessary to do the import of your feeds, but it's always a good idea to have your feeds backed up in an XML file.

Conclusion

I will continue using Google Reader to the last day, although I'm already using Feedly as a new reader. Sounds like a bad move and I resent Google's decision to terminate Reader, but this will give room for new products and new ideas from development enthusiasts to come to the scene.

Thanks for reading, looking forward to see your comments!

And, see you at MagmaConf!

902be69eb9ba93e412129d14010b48bf
Apr 30, 2013

Last Friday(04/27) a few co-workers and I were reviewing the RailsConf 2013 program and I found that it was very hard to see the schedule on my phone's small screen. When I tried to create a calendar of the talks I wanted to attend, I noticed that it wasn't possible.

The RailsConf site has a fixed width, so it's not easy to read on the small screen, so I thought - "there has to be an app for this". First I thought that I should contact the RailsConf organizers and make my request, then just sit and wait for the answer. That probably would have been easier, but then I thought to myself: "Wait a minute!, I'm a web developer, I build applications everyday, I write code, I know how to do it, I know how to write responsive CSS". So I decided to build this app.

Building the app sounds like a straightforward process, but it has a couple of complications, starting with the fact that I didn't have the program data, I tried inspecting the RailsConf Site's code looking for a JSON call or something similar, but I found nothing. I started to worry about it, because I really wanted to do this, but without the data it would be useless. Then one of my friends said joking: "you could perform a screen scrapping". That's a crazy idea; but it might work, I thought.

Then I remembered a post about screen scrapping so I went to Eduardo and asked him to do the scrapping and to provide me of a JSON with the data, which he did in a few minutes.

So now I have the JSON, and I just need to write the app to show the data.

I was there, creating my rails new and I really wanted to make something useful for me and everybody, and also to make it look good. I'm tired of Twitter's Bootstrap, 'cause now the internet looks all the same; so I found this new front-end framework which came very handy Gumby 2. It's really simple to use and it's written in Sass, which I love.

I wrote this is app this past Saturday and between Airports and Airplanes, fixed a couple of bugs during my trip to Portland, OR. 

Stop talking and show me the app!

just go to http://railsconfschedule.com/

image alt

Features?

  • It is a really simple app, it loads the data from of couple of JSONs and displays them nicely on the page.
  • It uses Omnioauth Authentication with Github as strategy.
  • You can build your day-by-day schedule. Add and Remove talks.
  • it is responsive, it looks beautiful in your phone, it actually looks better than the bigger screen, I think. ;)

image alt

TODO:
  • Show Talk description

  • Import to Google Calendar.

RailsConf now has an app, is it worth it?

It's totally worth it, I've build and app in just a day, I'm using it for managing my own schedule, and I have some pull request from a couple of friends who would like to help to make this better. And It was really fun.

Please Contribute

No matter if you think that the app is good or not, contribute to make it better! Fork the repo, hack a little bit and make it better!. Submit your pull request and help us with this project.

If you have never performed a pull request, I highly encourage you to go for this one, you could continue helping other projects after this, and the community will be thankful. It doesn't matter if you only fix a typo, or a security loophole... just go ahead and contribute.

Yo can find the code at https://github.com/hecbuma/railsconf/

Final words

If you identify a problem, and you have the tools and knowledge to solve it, go ahead and fix it!. You will be helping everyone. You may think that the problem is too simple to merit your contribution, but your work could be a lifesaver to the rest of us.

I hope you enjoy this app!

About Crowd Interactive

Crowd Interactive is a leading Ruby and Rails consultancy firm based in Mexico currently doing business with startups in the United States.

We specialize in building and growing Rails applications, by increasing your IT crew onsite or offsite. We pick our projects carefully, as we only work with companies we believe in.

You can find out more about us on our website.

Our Favorite Sites

Our conference

Conferences we attend

Stuff we've built

Earlier Posts