# Android

{% hint style="warning" %}
Morpheus環境におけるIMQA SDKを適用する方法を提供します。

[IMQA MPMインストールガイド](https://docs.imqa.io/imqa-guide/jpn/installation/android/mpm-sdk-install)により、IMQA agentコードを適用した後、この文書の内容を追加で適用してください
{% endhint %}

## 1. projectのbuild.gradleにinjectorを追加

projectのbuild.gradleにinjectorを追加した後、appのgradleに以下のようにライブラリ、ImqaBridgeを追加します。

{% hint style="warning" %} <mark style="color:red;">従来のガイドとは違って、pluginをapplyしません。</mark>

ファイルをアップデート後にGradleファイルを同期させる必要があります。
{% endhint %}

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

```gradle
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1' 
			  //お客様の環境に合うgradle tool
        ....
        classpath 'io.imqa:imqa-mpm-injector:2.25.6'

    }
}
```

{% endcode %}

## 2. appのgradleにライブラリを追加

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

```xml
//apply plugin: 'io.imqa'
//従来のガイドとは違って、pluginをapplyしません。

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'
		//最新のIMQA SDKの追加
}

//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. 作成される各webviewオブジェクトにImqaBridgeの追加

{% hint style="warning" %}
IMQABridgeの追加方法は、Morpheusを利用して開発されるケースによって異なる場合があります。
{% endhint %}

{% code title="webviewオブジェクトにおけるImqaBridgeの追加例" %}

```
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="継承構造で隠れたwebviewオブジェクトにおけるImqaBridgeの追加例" %}

```
getWebView().getSettings().setJavaScriptEnabled(true);
io.imqa.mpm.network.webview.WebviewInterface imqaJavascript = new
		io.imqa.mpm.network.webview.WebviewInterface();
getWebView().addJavascriptInterface(imqaJavascript, "ImqaBridge");
```

{% endcode %}

## \* Webview Agentの登録

Morpheusはサーバーからモバイルページを読み込む方式ではなく、モバイル内部にstaticファイルを置く方式です。ご提供するMorpheus用webview agentをすべてのページにおいてheadの一番上に位置するようにします。Morpheusの構造上、cdnを使用せず、直接リソースを挿入してください。


---

# 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/jpn/installation/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.
