# Android

{% hint style="warning" %}
이 문서는 모피어스 환경에서의 IMQA SDK를 적용하는 방법을 제공합니다.&#x20;

[IMQA MPM, Crash 설치 가이드](/imqa-guide/installation/android.md)를 통해 IMQA agent 코드 적용 후, 이 문서의 내용을 추가적으로 적용해주세요.
{% endhint %}

## 1. project의 build.gradle에 injector를 추가

project의 build.gradle에 injector를 추가 후 app의 gradle에 아래와 같이 라이브러리, ImqaBridge를 추가합니다.&#x20;

{% 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 추가 방법은 모피어스를 이용하여 개발되는 케이스마다 달라질 수 있습니다.
{% 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 등록

모피어스는 서버에서 모바일 페이지를 가져오는 방식이 아닌 모바일 내부로 static 파일을 내려놓는 방식입니다. 제공해 드리는 모피어스용 webview agent를 모든 페이지에 head의 최상단에 위치하도록 합니다. 모피어스 구조상 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/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.
