> For the complete documentation index, see [llms.txt](https://docs.imqa.io/imqa-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.imqa.io/imqa-guide/jpn/installation/cordova/android.md).

# Android

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

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

## 1. Gradle Pluginインストール&#x20;

「app.gradle」ファイルで「buildscript」内の「dependencies」ブロックに「imqa-mpm-injector」と上段に「plugin」を追加してください。一般的に「\<project\_dir>/app/build.gradle」にあります。

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

{% code title="app.gradle(project root)" %}

```java
// Add Build script dependencies 
buildscript { 
    repositories { 
        mavenCentral()
    } 
    
    dependencies {
    // Add dependencies.
        classpath 'io.imqa:imqa-mpm-injector:2.25.6' ... 
    } 
} 
```

{% endcode %}

* java

{% code title="app.gradle(app module) -> java" %}

```java
...
    dependencies {
    // Add 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'
    } 
} 

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 %}

* kotlin

{% code title="app.gradle(app module) -> kotlin" %}

```kotlin
...
    dependencies {
    // Add 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'
    } 
} 

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.kotlin,
                project.name,
                io.imqa.injector.GJavacAction.convertBuildType(variant.getBuildType()),
                io.imqa.injector.GJavacAction.makeFlavor(variant.getBuildType().name,
                        variant)
        ).execute(task)
    }
}
```

{% endcode %}

* java + kotlin

{% code title="app.gradle(app module) -> java + kotlin" %}

```java
...
    dependencies {
    // Add 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'
    } 
} 

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.kotlin,
                project.name,
                io.imqa.injector.GJavacAction.convertBuildType(variant.getBuildType()),
                io.imqa.injector.GJavacAction.makeFlavor(variant.getBuildType().name,
                        variant)
        ).execute(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 %}

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

```
...

project.home=Path of project (ex:/user/workspace/project1)
#Add only Kotlin project
project.kotlin.path=$PROJECT_HOME/app/build/tmp/kotlin-classes 
#Add only Java project
project.java.path=$PROJECT_HOME/app/build/intermediates/javac/debug/classes
#Path to built manifest file
project.manifest.path=$PROJECT_HOME/app/build/intermediates/merged_manifest/debug/AndroidManifest.xml
#gradle action
project.task.execute=:assemble
```

{% endcode %}

## 2. Android Manifestに権限追加&#x20;

AndroidManifest.xmlに発生したクラッシュ情報をアップロードするため、インターネット権限を与える必要があります。

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

```xml
<uses-permission android:name="android.permission.INTERNET"/>
```

{% endcode %}

## 3. Cordova Libraryの設定

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

### WebView HTTPのリクエスト

#### Web Serverの設定

WebViewデータを収集するときは、WebViewを提供するWebページにIMQA Webview Javascriptライブラリを挿入する必要があります。必要に応じてファイルをダウンロードし、Webサーバーから直接提供することができます。

(クロスオリジン問題が発生したとき、直接importして使うことをお勧めします。)

{% code title="Inserting a WebView file" %}

```
<!-- IMQA Webview Agent(1.1.3バージョン以下)です。 -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.2.js"
crossorigin></script>

<!-- minファイルを適用したい場合: -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.2.min.js"
crossorigin></script>
```

{% endcode %}

{% code title="index.html" %}

```html
<!-- IMQA Webview Agent(1.1.3バージョン以上)です。 -->
<script type="text/javascript" src="https://cdn.imqa.io/agent/webview-agent-1.1.3.js"
crossorigin></script>

<script>
    ((w, c, _wv, _w, _wk, _mh, _b) => {        
       w[_wv](w); // WebViewエージェント実行関数
    })(window, 'imqaClientConfig', 'IMQAWebviewMain', 'IMQAWebMain', 'webkit', 'messageHandlers', 'ImqaBridge')
</script>
```

{% endcode %}

#### Gradle( build.gradle )設定

Cordovaライブラリの内部においてIMQAコードを宣言できるよう、IMQA SDKを追加する必要があります。

{% code title="build.gradle ( Cordova Library ) " %}

```gradle
dependencies {
    ...
    Implementation 'androidx.appcompat:appcompat:1.3.0'

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

{% endcode %}

#### Android Agentを設定

MPMは、WebView関連ページおよびリクエストを収集します。収集するためには、Optionの設定とMPMWebviewInterfaceを追加する必要があります。

{% code title="org/apache/cordova/CordovaActivity.java" %}

```java

..

protected void init() {
   appView = makeWebView();
   createViews();
   if (!appView.isInitialized()) {
       appView.init(cordovaInterface, pluginEntries, preferences);
   }
   cordovaInterface.onCordovaInit(appView.getPluginManager());

   // Inserting WebView Interface (ImqaBridge required)
   WebView wV = (WebView) appView.getEngine().getView();
   wV.addJavascriptInterface(new     io.imqa.mpm.network.webview.WebviewInterface(),"ImqaBridge");
   // Wire the hardware volume controls to control media if desired.

   String volumePref = preferences.getString("DefaultVolumeStream", "");
   if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
       setVolumeControlStream(AudioManager.STREAM_MUSIC);
   }
}
```

{% endcode %}

{% code title="org/apache/cordova/engine/SystemWebviewEngine.java" %}

```

..

private static void exposeJsInterface(WebView webView, CordovaBridge bridge) {
   if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)) {
       LOG.i(TAG, "Disabled addJavascriptInterface() bridge since Android version is old.");
       // Bug being that Java Strings do not get converted to JS strings automatically.
       // This isn't hard to work-around on the JS side, but it's easier to just
       // use the prompt bridge instead.
       return;
   }
   SystemExposedJsApi exposedJsApi = new SystemExposedJsApi(bridge);

   // Inserting WebView Interface (ImqaBridge required)
   webView.addJavascriptInterface(new io.imqa.mpm.network.webview.WebviewInterface(),"ImqaBridge");

   webView.addJavascriptInterface(exposedJsApi, "_cordovaNative");
}

```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.imqa.io/imqa-guide/jpn/installation/cordova/android.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
