(This post will guide reader to setup Jenkins with Gradle /Android Studio and GitHub)
Recently google is pushing gradle based build system and it certainly looks ominous. I decided to give Jenkins, gradle and github integration spin for some personal & professional interests. Here is the guide as a result of that research.
Background:
- Jenkins is a continuous Integration tool which comes with tons of plugins which can help automate up your build & testing process.
- Robotium is a UI Automation tool. Robotium lets you do automated UI testing by writing bunch of test cases.
- Android Studio is an improved IDE used for developing applications for Android
- Gradle is a toolchain which can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else.
If you have not written & run any tests yet using Android Studio. It might be wise to visit my previous blog for the setup. We will use the project from that setup. I will provide sources at a later point in time.
To follow along lets asume we have the sources from my previous blog. The relevant contents would be as follows --
Git Repo -- <Your repository>
Main Package -- com.meta.twitterlist
Test Package -- com.meta.twitterlist.test
build.gradle -- Sample build.gradle which we will use
Android SDK : Installed at d:\Android. SDK 20 installed with v4.20 support libraries.
Now steps for the actual Integration with Jenkins on windows. Similar steps can be used to install on other OS --
- Install Jenkins from Jenkins website
- Setup Security which suits your organisational needs.
- Install following Plugins for Jenkins by going to (Manage Jenkins -> Manage Plugins) -
- Github plugin -- It will get all other relevant Git related plugins.
- Green Balls -- To Mark passed tests as green instead of blue
- Gradle Plugin -- For running gradle builds.
- Environment Injector Plugin -- For Injecting Environment variables before build
Now we are ready to create a job which will download code from github, build it and run tests on device.
- Create a new job / item
- Item Name: AndroidGithub
- Build a free-style software project
- Configure System
- Manage Jenkins -> Configure System
- Ensure git.exe path is set under git section
- Configure the job
- My View -> AndroidGithub
- Configure
- Source Code Management -> Git
- Repository URL -- <Your Repository>
- Credentials -> Advanced -- <Set your credentials for the repo>
- Set Build steps
- Inject Environment Variables
- Properties Content -- ANDROID_HOME = <path to your sdk>
- Invoke Gradle Script
- Use Gradle Wrapper
- Check mark : "From Root Build Script dir"
- Tasks : clean app:assembleDebug :app:assembleDebugTest connectedCheck uninstallDebug uninstallDebugTest connectedAndroidTest
- Apply & Ok
- Now click "Build Now" and if everything is done correctly the tests should run.
- If your tests ran properly on the device, you should be able to see the results at following path (<path of Jenkins>/jobs/AndroidGithub/workspace/app/build/outputs/reports/androidTests/connected/index.html)
Thats it in 5 steps we have successful jenkins, github, gradle integration for Android tests.
If more details about gradle tasks are needed here is a good blog. Or Android also has good documentation on tools.android.com