# Android

{% hint style="warning" %}
This document provides instructions on how to apply IMQA SDK in the React Native environment.

After applying the IMQA agent code with reference to the IMQA MPM Installation Guide, please follow further the instructions of this document.
{% endhint %}

## 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.

{% hint style="warning" %} <mark style="color:red;">Do not apply the plugin – different from the previous guide.</mark>

The gradle file should be synchronized after updating the file.
{% endhint %}

{% code title="build.gradle" %}

```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'

    }
}
```

{% endcode %}

## 2. Add the library to your app’s gradle

{% code title="AndroidManifest.xml" %}

```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)
    }
}

```

{% endcode %}

## 3. Add ImqaBridge to each WebView object created

{% hint style="warning" %}
How to add IMQABridge may vary depending on development using Morpheus.
{% endhint %}

{% code title="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");

```

{% endcode %}

{% code title="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");
```

{% endcode %}

## 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.imqa.io/imqa-guide/eng/installation-guide/morpheus/android.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
