Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Automated Android APK Packaging with QR Code Generation Using Jenkins

Tech 1

Overview

The process involves using Jenkins with Gradle to compile Android APK files. A Python library called myqr generates QR codes that link to these packages. These QR codes are then served through an Nginx web server, allowing users to scan and download the APKs directly.

Prerequisites

  • CentOS 6.6
  • Android SDK (available from the official Android developer site)
  • Gradle distribution matching your project's requirements
  • Jenkins 2.73.3 installed via RPM
  • Java Development Kit 8
  • Python 3 environment setup
  • Required Python packages: myqr and Pillow
  • Nginx configured for static file serving

After installation, update /etc/profile with necessary environment variables:

export JAVA_HOME=/usr/java/jdk1.8.0_101
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export ANDROID_HOME=/opt/SDK
export PATH=$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH

Apply changes with source /etc/profile

Jenkins Configuration

Required plugins include:

  • Email Extension Plugin
  • Subversion Plug-in
  • Description Setter Plugin

Navigate to Manage Jenkins > Configure Global Security and System Settings to configure email notifications.

Set default subject line as ${BUILD_STATUS} - ${PROJECT_NAME} - Build # ${BUILD_NUMBER}

For default content, use HTML template including build status, project name, build number, SVN revision, trigger cause, URLs for console output and workspace, change history since last successful build, failed test results, and last 100 lines of build log.

Under Manage Jenkins > Global Tool Configuration, set up Gradle module.

Create a new freestyle project. Source code management settings like SVN/Git should be configured according to repository specifics.

In the build step section, select "Invoke Gradle script". Use default Gradle version due to known issues with custom installations. Set root build script path to ${WORKSPACE} and specify the build.gradle file under the app directory.

To prevent caching when generating QR codes, remove previous images before creating new ones:

BUILD_TIME=$(date +%F-%H-%M-%S)
echo $BUILD_ID
rm -f /data/download/images/test.jpg

cp ${WORKSPACE}/app/build/outputs/apk/app-release.apk /data/download/android/${BUILD_TIME}-app-release.apk
myqr http://192.168.0.152:9090/${BUILD_TIME}-app-release.apk -n ${BUILD_ID}-test.jpg -d /data/download/images

Post-build actions can embed generated QR codes into emails:

<img src='http://192.168.0.152/${BUILD_ID}-test.jpg' width=200px height=200px>

Add this snippet to email templates to allow recipeints to scan and download APKs immediately.

QR Code Generation Setup

Install Python 3 and pip, ensuring proper environment configuration. Install required libraries:

pip install -I --no-cache-dir -v Pillow
pip install myqr

Link myqr executable to system binaries:

ln -s /usr/local/python/bin/myqr /usr/bin/

Refer to myqr documentation for detailed usage instructions.

Web Server Configuration

Configure Nginx to serve both QR code images and APK downloads. Sample configuration includes two server blocks: one for image assets and another for downloadable files.

Image server listens on port 80, maps requests ending in common graphic formats to /data/download/images/. It handles proxy storage and buffering configurations apropriately.

Download server runs on port 9090, enables directory listing at /data/download, showing human-readable timestamps instead of GMT times.

Full Nginx config demonstrates optimized performance parameters such as connection limits, timeouts, compression settings, and buffer sizes tailored for efficient delivery of mobile application packages.

Tags: Jenkins

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.