Android

Install SDK in Morpheus Environment

1. Add injector to build.gradle in project

After adding injector to your project’s build.gradle, add the library and ImqaBridge to your app’s gradle as shown below.

build.gradle
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1' 
			  // Gradle Tools Suitable for Client Environment
        ....
        classpath 'io.imqa:imqa-mpm-injector:2.25.6'

    }
}

2. Add the library to your app’s gradle

AndroidManifest.xml
//apply plugin: 'io.imqa'
//Do not apply the plugin – different from the previous guide.

dependencies {
    ...
    implementation 'io.imqa:imqa-core:2.27.5'
    implementation 'io.imqa:imqa-mpm-client:2.27.9'
    implementation 'io.imqa:imqa-crash-client:2.27.5'
		//Add the Latest IMQA SDK
}

//Add the following code under dependency
io.imqa.IMQAPlugin imqaPlugin = new io.imqa.IMQAPlugin()
imqaPlugin.init(project)
new io.imqa.injector.GJavacAction(project.name).setConfiguration(project)
android.applicationVariants.all { variant ->
    variant.javaCompile.doLast { task ->
        new io.imqa.injector.CompileAction(
                io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.javacClasses,
                project.name,
                io.imqa.injector.GJavacAction.convertBuildType(variant.getBuildType()),
                io.imqa.injector.GJavacAction.makeFlavor(variant.getBuildType().name,
                        variant)
        ).execute(task)
    }
}

3. Add ImqaBridge to each WebView object created

Example of adding ImqaBridge to a WebView object
mWebView.addJavascriptInterface(new AndroidBridge(), AndroidBridge.KEY_NAME);
.
.
.
io.imqa.mpm.network.webview.WebviewInterface imqaJavascript = new
        io.imqa.mpm.network.webview.WebviewInterface();
mWebView.addJavascriptInterface(imqaJavascript, "ImqaBridge");
Example of adding ImqaBridge to a WebView object hidden in the inheritance structure
getWebView().getSettings().setJavaScriptEnabled(true);
io.imqa.mpm.network.webview.WebviewInterface imqaJavascript = new
		io.imqa.mpm.network.webview.WebviewInterface();
getWebView().addJavascriptInterface(imqaJavascript, "ImqaBridge");

Register WebView Agent

Morpheus drops static files inside the mobile instead of fetching mobile pages from the server. Place the WebView agent for Morpheus we provide at the top of the head on all pages. Due to the structure of Morpheus, we recommend not using cdn but injecting the resources by yourself.

Last updated