# Installing Crash SDK

If you add IMQA Crash to an Android project, you can check the performance issues of the application, which occur in the app developed with Java or Kotlin, in various viewpoints.

{% hint style="warning" %} <mark style="color:red;">**This is not required for Android if you have already installed the MPM.**</mark>
{% endhint %}

{% hint style="warning" %}
Please install Crash SDK after creating an iOS project at the IMQA project page and receiving the project key.
{% endhint %}

## 1. Installing the SDK <a href="#sdk" id="sdk"></a>

Generally, it can be found in “\<project\_dir> /app/build.gradle”.

• Open the “app.gradle” file in Android Studio.\
• Add “mavenCentral()” to the repositories.\
• Add “imqa-crash-client” to the dependencies.

{% hint style="warning" %}
The gradle file should be synchronized after updating the file.
{% endhint %}

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

```css
// Add jcenter repository
repositories {
    mavenCentral()
}

// Add compile or implementation dependencies
dependencies {
    compile 'io.imqa:imqa-core:2.27.4'
    compile 'io.imqa:imqa-crash-client:2.27.4'

    // Add when using zstd
    implementation 'com.github.luben:zstd-jni:1.5.2-3@aar'
}

```

{% endcode %}

## 2. Basic setting <a href="#setting" id="setting"></a>

### Internet setting <a href="#internet" id="internet"></a>

Add Internet authority to the “AndroidManifest.xml” project to upload occurred crash information.

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

```xml
<uses-permission android:name="android.permission.INTERNET" />
<!-- To view the LogCat contents -->
<uses-permission android:name="android.permission.READ_LOGS"/> 
```

{% endcode %}

### Initializing IMQAController <a href="#controller" id="controller"></a>

Insert codes that initialize IMQAController into the “Application” class of the project. You can receive PROJECT\_KEY after creating a project on the IMQA website.

{% code title="MyApplication.java" %}

```javascript
...
  @Override
  public void onCreate() {
      super.onCreate();
      io.imqa.crash.IMQACrashAgent.InitializeAndStartSession(
          this,
          BuildConfig.FLAVOR,
          "PROJECT_KEY");
  }
...
```

{% endcode %}

{% code title="MyApplication.kt" %}

```kts
...
  override fun onCreate() {
      super.onCreate()
      io.imqa.crash.IMQACrashAgent.InitializeAndStartSession(
          this,
          BuildConfig.FLAVOR,
          "PROJECT_KEY")
  }
...
```

{% endcode %}

### **⚠️ HTTPS (API level > 27)** <a href="#https" id="https"></a>

The HTTPS request is required from Android API level 28 and above due to the enhanced network security policy. The following measures are needed to meet the requirement:

1. **Authenticated HTTPS request**\
   Request authenticated HTTPS to the IMQA server to collect the data normally.

{% code title="MyApplication.java or MyApplication.kt" %}

```kotlin
...
imqaOption.setServerUrl('https://collector.imqa.io');
...
```

{% endcode %}

2. &#x20;**Forced HTTP request**\
   &#x20; You can allow all cleartext HTTP traffic by setting this flag.

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

```xml
...
<application
    ...
    android:usesCleartextTraffic="true"
    />
...
```

{% endcode %}

### Using Zstandard (Zstd)

You can use Zstandard, which is an algorithm enabling more secure and efficient data compression, instead of the typical gzip. To use it, you need the following settings:

**• Setting the MPM Mode Optio**n\
&#x20;You can set whether to use Zstd in the settings when inserting the IMQA startup code.

{% code title="MyApplication.java or MyApplication.kt" %}

```
...
imqaOption.setCompressZstd(true);
...
```

{% endcode %}

**• Add Zstd Library**\
&#x20;In the “app.gradle” file, add the “zstd-jni” aar library to the “dependencies” block in “buildscript”.

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

```
...
    dependencies {
    // Add dependencies.
       ...
       implementation 'com.github.luben:zstd-jni:1.5.2-3@aar'
       ...
    } 
} 
```

{% endcode %}

## **3.** ProGuard setting <a href="#proguard" id="proguard"></a>

ProGuard is a tool used to make the APK as small as possible in size by removing unused resources and shortening the name of classes or methods. When using ProGuard or DexGuard, the original class and method name can be displayed on the crash report by uploading the mapping file as below:

### Preparation <a href="#preparation" id="preparation"></a>

If ProGuard is used in a project under development, the source code is obfuscated, making the analysis difficult. In this case, obfuscated codes can be analyzed using the generated mapping.txt file.\
Add the following to ProGuard rules (proguard-rules.pro):

{% code title="proguard-rules.pro" %}

```processing
  -keepattributes SourceFile,LineNumberTable
  -printmapping map.txt

  # IMQA Proguard
  -keep class io.imqa.** { *; }
  -dontwarn io.imqa.**

  # okhttp3 Proguard
  -dontwarn okhttp3.**
  -dontwarn okio.**p
```

{% endcode %}

A file is created in the app/build/outputs/mapping/debug (or release)/mapping.txt directory. (The file location may differ a little depending on the buildType and flavor.) You need to connect to <http://crash.imqa.io> to upload the file created in this way.

{% hint style="danger" %}
When uploading the file, its name must be named as “mapping.txt” or “map.txt”.
{% endhint %}

### Upload process <a href="#upload" id="upload"></a>

&#x20;1\. Select “Setting” at the project menu.

<figure><img src="https://lh7-us.googleusercontent.com/xgg8B-GoeojZd14RjckW76RT9n23Y26l7aPVO9L1NT53zCGL6BoVVbIdLunQLHzBz9PIkbrcMAAm2n60vfd8BidcXksfWTCv9wGfpnDJfAhUfyX9PfvSJNLWCzLhqcZVAUdi8F8L9KDHS402Ju8IXA" alt=""><figcaption></figcaption></figure>

&#x20;2\. Click the \[File Upload] button to open the upload window.

<figure><img src="https://lh7-us.googleusercontent.com/3JENlqGoVpFCkmcnOJaYOa2kSU8XZBP95UZEYG8BGcV6GzSb4w8B3TWpPy5QC6ZkdiMx6lCtpwP7IZ_TT2PtprMZVIHLbtm40VVrnS8gA2aEXWejyc_xeVdqrYfzX-IqRi6Qk8OE776rLE0UHzGXfA" alt=""><figcaption></figcaption></figure>

3\. Click the \[Choose File] button that matches the app version specified in the gradle and upload the “mapping.txt” file.

<figure><img src="https://lh7-us.googleusercontent.com/JwXDqUBe33WN268r4arHQarIKcqtgV4IFGA1ce74NyOhspUrnVe9X4g1pZM_e113YwnaqcZ1q8IJSiZA3ru0wwWU0FdmMX4boqDsbLLba_WJw6axRloFzcNzf4wQ_WI9rCn3LJgkMZQpIeT_BPWcrA" alt=""><figcaption></figcaption></figure>

&#x20;4\. If you click the \[Upload] button, the crash information collected afterwards will be displayed after analysis.

{% hint style="warning" %}
When the latest version of the app is released, please register additional mapping files of the same app version in order to view the version’s crash information.
{% endhint %}

## 4. Settings required for the installation-type

Any client who selects an IMQA installation-type must set the collection server.

{% code title="MyApplication.java" %}

```java
@Override
public void onCreate() {
    super.onCreate();
    io.imqa.core.IMQAOption imqaOption = new io.imqa.core.IMQAOption();

    /*
     * Default value : 'https://collector.imqa.io'
     * String : Server information
     */
    imqaOption.setCrashServerUrl('https://(ipaddress)');

    io.imqa.crash.IMQACrashAgent.InitializeAndStartSession(
        this, // Application Context
        BuildConfig.FLAVOR, // Project Flavor Setting
        "PROJECT_KEY",  // Issued project key
        imqaOption // Add an object when the option is set
    );
}
```

{% endcode %}
