Android Continuous Integration

Source: Internet
Author: User
Tags hockeyapp

As the Android platform matures, with a series of launches for Android testing frameworks, developers are finally able to do unit testing, integration testing, and functional testing on mobile development. In the agile process, from development, to testing, to acceptance eventually becomes the release version of user-oriented, experience is the story of a complete life cycle. CI (continuous integration, continuous delivery) has also played a very important role in agile practice.

If the continuous integration of the web, as well as a variety of testing frameworks have a certain historical accumulation. The continuous integration of Android can be a novelty, and most IT companies know how to perform a series of automated tests on the server side or Web side to ensure their functionality is correct. And for the mobile side of the product is more than the test personnel composed of human flesh test. This kind of manual testing on the mobile side, whether it's for testers or developers who want to pack up and fix bugs all the time, costs a lot.

Starting with Android 2.3.3, I became a developer of Android. From the developer's point of view, Android's step-by-step upgrade, but also from the perspective of ordinary users of Android in the low-end market dominance. While I'm happy with Apple's products, I can't give up on my Android feelings. I'm glad I'm finally able to see the practice of test-driven development on Android, and I'm thankful that I have the opportunity to practice and learn from scratch and learn about the continuous integration of Android.

Objective

This article focuses on starting from scratch and explores how to build an available Android CI environment with the learner's role. The final goal is to start the build unit test on Jenkins, to run the functional test, and finally compile the QA version for the QA test by a one-click Deployment, available for release release version, and generate downloadable links with Hockeyapp.

    1. Build a simple app prototype that includes unit testing and integration testing.
    2. Run the Ubuntu virtual machine locally via vagrant and install the Jenkins Server and install the Android operating environment on Ubuntu.
    3. Create Android Pipeline, Android Build, Android functional Test, Android Deploy Hockey App in Jenkins.
    4. Create different environment variables in the Android project, making it possible to choose different build variables and build apps in different environments, such as QA and release.
1. Build Android infrastructure, run tests locally

The basic engineering here mainly refers to the ability to run the basic functions of the test, I choose to use Robolectric to do unit testing, using espresso to do the inheritance test (the following article will also explore the use). The basic project mainly refers to the robolectric/decard-gradle, through some gradlew configuration, so that our project can directly run unit testing and integration testing.

To run unit tests:

./gradlew test

Run the espresso test:

./gradlew connectedAndroidTest

Once you run this instance successfully, it means that this step has actually been completed. We only need to run these commands through Jenkins and then show the results.

2. Install the Jenkins and Android environments in the virtual machine

In order to start from scratch, I chose a clean ubuntu/trusty machine, in order to make the construction from scratch, we can better simulate the real situation of our EC2 machine
Shape. From a test point of view, I chose to use vagrant to start the virtual machine.

Xiaoming:ci minggong$ vagrant init ubuntu/trusty64a ' vagrantfile ' hasbeen placedinchThis directory. You are Nowready to' Vagrant up ' your firstVirtualenvironment! PleaseReadThe commentsinchThe Vagrantfile asWell asDocumentation on' Vagrantup.com ' forMore information on usingVagrant.XiaoMing:ci minggong$ Vagrant upbringing Machine' Default 'Up with ' VirtualBox 'Provider ... [default] Importing base box' ubuntu/trusty64 '... [default]MatchingMAC Address forNAT Networking ... [default] Setting the name ofThe VM ... [default] Clearing any previouslySetForwarded ports ... [default] Fixed Port collision for  A=2222. Now onPort2200. [default] Creating Shared Folders metadata ... [default] Clearing any previouslySetNetwork Interfaces ... [default] Preparing Network interfaces based onConfiguration ... [default] Forwarding Ports ... [default] -- A=2200(Adapter1)[default] Booting VM ... [default] Waiting forMachine toBoot. This May TakeA few minutes ... [default] Machine booted andready! [default] Mounting Shared Folders ... [default]--/vagrantxiaoming:ci minggong$ vagrant Sshwelcome toUbuntu14.04LTS (Gnu/linux3.13.0- --generic x86_64) * Documentation:https://help.ubuntu.com/Last Login:tue APR A  +: -: the  the  from 10.0.2.2

If a static IP is already set in the Vagrantfile, you can log in directly via IP. Vagrant Default User name vagrant , password is vagrant .

vagrant sshafter you log on to the virtual machine, you start to install various environments:

    • Java
    • Jenkins
    • Android Environment
2.1 Installing Java

Apt-get Direct installation of jdk1.7:

Vagrant@ubuntu- -:~$ sudo apt-get updatevagrant@ubuntu- -:~$ sudo apt-get install openjdk-7-jdk-yvagrant@ubuntu- -:~$ Java-versionjava version"1.7.0_75"OpenJDK Runtime Environment(IcedTea 2.5.4) (7u75-2.5.4-1~TRUSTY1)OpenJDK  --Bit Server VMS(Build24.75-B04, Mixed mode)
2.2 Installing Jenkins

Refer to the Official Jenkins Tutorial:

-q-O- https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add --c‘echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list‘sudo apt-get updatesudo apt-get-y

After you install Jenkins, first verify that Jenkins is installed, and curl http://localhost:8080 if you find that you can output a bunch of HTML tags, then it proves that Jenkins has been successfully installed and started. The common use commands for Jenkins are as follows, starting at port 8080 by default:

vagrant@ubuntu-14:~$ sudo /etc/init.d/jenkins -helpUsage: /etc/init.d/jenkins {start|stop|status|restart|force-reload}

Jenkins default de configuration file is /etc/default/jenkins , you can see the path defined by Jenkins_home:

#jenkins home location JENKINS_HOME=/var/lib/jenkins

If you need to change the default Jenkins home path, you need to change the /etc/default/jenkins address and then restart Jenkins to take effect.

2.3 Installing the Android operating environment

The final step is to install the Android operating environment so that our Jenkins can run the relevant tests for Android. Main reference article how to Build Apps with Jenkins

    • Find the latest SDK installation package address on the Android SDK website: http://dl.google.com/android/android-sdk_r24.1.2-linux.tgz, download and unzip:
$ cd /opt$ sudo wget http://dl.google.com/android/android-sdk_r24.1.2-linux.tgz$ sudo tar zxvf android-sdk_r24.1.2-linux.tgz$ sudo rm android-sdk_r24.1.2-linux.tgz
    • Set the android environment variable:
$ vi /etc/profile.d/android.sh

Add the following to android.sh file

export ANDROID_HOME="/opt/android-sdk-linux"export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"

Then source /etc/profile , make the file effective.

    • Configuring the Android SDK

The easiest way to do this is to download all of the SDKs and related tools, and of course you can download them all by yourself, referring to this article. I use the direct update all method:

update sdk --no-ui

After a long wait, after the download is finished, this part of the work is basically completed. (This step is usually left in the middle of the night to download)

2.4 Installing Git

To enable Jenkins to download code directly from Git repository, you need to install Git in Ubuntu:

sudo apt-get updatesudo apt-get-y
2.5 Configuring Jenkins

After Jenkins starts, register the logged-in user first, and then create a new build Project. The construction is basically done. Of course you can also find some plugins in the previous blog Set up Jenkins for Android integration using Docker, through which the plug-ins can better achieve the continuous integration of Android, including through the hockey App Continuous release of the new version.

For specific installation details, you can refer to the setup Android CI using Docker

Roughly speaking, install the plugin:Git plugin, Android emulator plugin, Copy artifact plugin, Android lint plugin, Hockey app plugin, Build monitor plugin

The runtime discovers that the Jenkins user does not have permission to operate on the Jenkins-home directory and needs to increase permissions through chmod. Under the current vagrant user, you su jenkins can switch to the Jenkins directory, but you need to provide a password. So you can change your password yourself:

vagrant @ubuntu -14  :/var/lib/jenkins  $  sudo passwd jenkinsenter  new unix  password:  retype  new UNIX  password:  PASSWD:  Password updated Successfullyvagrant @ubuntu -14  :/var/lib/jenkins  $  su jenkins Password  :  jenkins @ubuntu -14  :~  $  

Once the permissions have been set successfully, run the test again, prompting Android Build tools not to install successfully:

withan‘:app‘to21.1.2

The version number of Android build tools is the 21.1 that we specified in App/build.gradle. 2. By android list sdk --all being able to view all the list of SDKs that can be downloaded.

Packages Available for installationorUpdate138   1-Android SDK Tools, revision24.1. 2   2-Android SDK Platform-tools, revision A   3-Android SDK Build-tools, revision22.0. 1   4-Android SDK Build-tools, revision A(Obsolete)5-Android SDK Build-tools, revision21.1. 2   6-Android SDK Build-tools, revision21.1. 1(Obsolete)7-Android SDK Build-tools, revision21.1(Obsolete)8-Android SDK Build-tools, revision21.0. 2(Obsolete)9-Android SDK Build-tools, revision21.0. 1(Obsolete)

You can see that the index value of 21.1.2 is 5, so you can use the android update sdk -u --all --filter <number> update to discover that a permissions issue has occurred.

Installing Archives:  to install archives  Downloading Android SDK Build-tools21.1.2  not found: /opt/android-sdk-linux/temp/build-tools_r21.1.2-linux.zip (Permission denied)  Done. Nothing was installed.

You can add 777 permissions to/opt/android-sdk-linux and its subfolders directly under the current user.

-R777 /opt/android-sdk-linux

Then install Android build Tools 21.1.2, android update sdk -u --all --filter 5 . Errors may also occur after the installation is complete:

:app:mergeDevDebugResources FAILEDFAILURE: Build failed with an exception.* ‘:app:mergeDevDebugResources‘‘command ‘/opt/android-sdk-linux/build-tools/22.0.1/aapt‘‘

Google, only to find that Android in 64 for the Linux machine run on the problem, need to install ia32-libs , but through apt installation is told that Ia32-libs does not exist, unable to install. The StackOverflow solution is as follows:

-icd /etc/apt/sources.list."deb http://old-releases.ubuntu.com/ubuntu/ raring main restricted universe multiverse">ia32-libs-raring.listapt-get updateapt-get install ia32-libs

After the installation is successful, the Android unit test runs successfully.

After the unit tests, we often need to run functional tests, which need to open the simulator when the function is tested. That is headless Android emulator. First create the AVD in the virtual machine, and then start the Run emulator.

Before running, you need to install the API-21 corresponding armeabi-v7a before you can create a virtual machine. By looking to android list sdk --all know that its corresponding serial number is 68, you can install it via Android Update:

androidupdatesdk-u--all--filter68

After the installation is complete, create the API-21 virtual machine:

-f-a-s1080-n Nexus-21-t android-21--abi

The virtual machine needs to be opened after it is successfully created:

-avd Nexus-21-no-skin-no-audio-no-window

If it goes well, the functional test should be able to run as well. But in my virtual machine there is no way to start Android emulator. It looks like you want to build a real Android functional test, or use a Mac mini with a monitor to run the comparison.

3.Other

How to configure different flavor in Android, how to upload the built-in app to Hockeyapp. Welcome to view my blog.

Android Continuous Integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.