3. Mobile eXplorer Agent Integration for Android using Android Studio IDE (IntelliJ IDE)

Notes: if you are developing mobile application that target Android 6 or later that integrates with Mobile eXplorer Agent, make sure you enable app permissions on Android 6.0+ devices when deploying your application to that Android device.

This section will show you how to integrate qTest Mobile eXplorer Agent to your application on Android devices in Android Studio.

Important Notes:

  • IntelliJ IDE can open Eclipse project. We don’t support integration for this type and recommend you to using Eclipse IDE instead (Please go back to section 5.1)
  • If you want to convert it to Android Studio IDE, please follow instruction in Android Developer Site: https://developer.android.com/sdk/installing/migrate.html

These are the steps that you need to go thru:

 

Required Environment

  • IDE:
    • AndroidStudio: 1.0.+
    • IntelliJ CE 14.0.+/ IntelliJ Ultimate 14.0.+
    • Old versions: please lookup Question 3 in Trouble Shooting.
  • Gradle
    • AndroidStudio: 1.0.+
    • IntelliJ: 0.14.+
  • Android SDK
  • Android NDK
  • Android Build Tool 21.1.2
  • Android Support Library 21.0.3

You have to make sure your project work properly before we go to steps below.

 

Step 1: Download Mobile eXplorer Agent

In first step, you need to download the Mobile eXplorer Agent from HERE

 

Step 2: Add Mobile eXplorer Agent to your project

    • Extract “Mobile_eXplorer_Agent_AndroidStudio.zip” archive file, you will get folder with name “Mobile_eXplorer_Agent_AndroidStudio”
    • Open your project in Android Studio/IntelliJ
    • Copy “Mobile_eXplorer_Agent_AndroidStudio” folder to your project root folder. In Mac you can use Finder, in Windows you can use Explorer to do that

    • Back to Android Studio/IntelliJ, project will auto refresh, if not you have to refresh by click File->Synchonize
    • Open Project Panel->Select Project in Combo Box, you can see a folder “Mobile_eXplorer_Agent_AndroidStudio”

  • Change “Mobile_eXplorer_Agent_Studio” to Android Library Module.
    • Open “setting.gradle” file, this file is in your root project folder
    • Append this script to the end of line:
      ':Mobile_eXplorer_Agent_AndroidStudio'
      

      Example: My “setting.gradle” file

      include ':app', ':Mobile_eXplorer_Agent_AndroidStudio'
      
    • After you change .gradle file, AndroidStudio/IntelliJ will ask you to sync gradle files ' Select Sync Now in top right window.
    • After Sync gradle files ' Mobile_eXplorer_Agent_AndroidStudio became a module (bold).

  • To avoid effective to your project, we suggest you create new build flavor from active flavor to enable Mobile_eXplorer. If your project has multiple flavors, clone a flavor from active flavor. Otherwise you have to create 2 flavors, one will run without Mobile eXplorer Agent (active flavor) and another one will run with Mobile eXplorer Agent.
    • Open your main module “build.gradle” file.
    • Create an empty flavor (in case you don’t have any flavor): In android tag add this scripts:
      productFlavors {
      
              //active flavor
              activeFlavor {
      
              }
      }
      
    • Clone active flavor and name it to “mobileExplorer”
      productFlavors {
      
              //active flavor
              activeFlavor {
      
              }
      
              //build flavor that enable Mobile eXplorer
              mobileExplorer {
              }
        }
      
    • Add these scripts to flavor “mobileExplorer”
                  //enable aspectJ run in your app
                  apply plugin: 'android-aspectj'
      
                  //enable native renderscript
                  renderscriptNdkModeEnabled true
                  renderscriptSupportModeEnabled true
                  renderscriptTargetApi 21
      
                  dependencies {
                      //compile module Mobile_eXplorer_Agent_AndroidStudio
                      mobileExplorerCompile project(':Mobile_eXplorer_Agent_AndroidStudio')
                  } 
      
    • Add repository jcenter (if it’s missing)
      repositories {
           jcenter()
      }
      
    • Add AspectJ dependency in buildscript tag:
      dependencies {
              classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.5'
          }
      
    • Add Maven Repository in buildscript tag (if it’s missing)
      repositories {
          mavenCentral()
      }
      

      Example: After change build script, my main module “build.gradle” looks like:

      repositories {
           jcenter()
      }
      buildscript {
          //add Maven repo
          repositories {
              mavenCentral()
          }
      
          //add AspectJ dependency
          dependencies {
              classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.5'
          }
      }
      
      apply plugin: 'com.android.application'
      
      android {
          compileSdkVersion 21
          buildToolsVersion "20.0.0"
      
          defaultConfig {
              applicationId "lelee.cardsaganistandroid"
              minSdkVersion 15
              targetSdkVersion 21
              versionCode 1
              versionName "1.0"
          }
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
              }
          }
      
          productFlavors {
      
              //active flavor
              activeFlavor {
      
              }
      
              //build flavor that enable Mobile eXplorer
              mobileExplorer {
                  //enable aspectJ run in your app
                  apply plugin: 'android-aspectj'
      
                  //enable native renderscript
                  renderscriptNdkModeEnabled true
                  renderscriptSupportModeEnabled true
                  renderscriptTargetApi 21
      
                  dependencies {
                      //compile module Mobile_eXplorer_Agent_AndroidStudio
                      mobileExplorerCompile project(':Mobile_eXplorer_Agent_AndroidStudio')
                  }
              }
          }
      }
      
      dependencies {
          compile fileTree(dir: 'libs', include: ['*.jar'])
          compile 'com.android.support:appcompat-v7:21.0.3'
      }
      
    • Sync your project gradle files, you can see in Build Variants Panel, your main module will have multiple build variants, if you select build variant start with “mobileExplorer” when run “app”, “Mobile_eXplorer_Agent” will be enable and be able to run, otherwise it cannot run and do not effect to your app.
  • If using IntelliJ IDE, change module “Mobile_eXplorer_Agent_AndroidStudio” build script file.
    • Open “build.gradle” file of “Mobile_eXplorer_Agent_AndroidStudio” module.
    • Change android build gradle version to the same with your project.

      Example:

      classpath 'com.android.tools.build:gradle:0.14.0'
      
    • Provide SDK & NDK local location in global local.properties file. This file is located in project root folder. If it is not exist, please create it.

      Example: this file in my test project (in a Mac computer)

      sdk.dir=/Volumes/DATA/dev/android-sdk-macosx
      ndk.dir=/Volumes/DATA/dev/android-ndk-r9d
      

 

Step 3: Enable Mobile eXplorer Agent on your app

  • Configure Mobile eXplorer Settings
    • Open mexplorer_config.properties. This file is located in Mobile_eXplorer_Agent_AndroidStudio/src/main/assets/mexplorer_config.properties. Change this file like this code:
      QTEST_HOST=[Provide qTest Link]
      QTEST_DEFAULT_USER_NAME=[Provide qTest Default Account]
      QTEST_DEFAULT_PASSWORD=[Provide qTest Default Password]
      THEME=[dark/light]
      

      Example: The configuration below, we using in beta site:

      QTEST_HOST=https://beta-mexplorerdemo.qtestnet.com
      QTEST_DEFAULT_USER_NAME=mexplorer_demo@mailinator.com
      QTEST_DEFAULT_PASSWORD=admin123
      THEME=dark
      

 

Step 4: Build and Release your application

Now you finish integrating Mobile eXplorer into your testing application, please build and run.