Android

Install SDK in React Native Environment

IMQA SDK Installation Guide_React_Native provides instructions for applying 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.

1. Common

MPM Module install

To apply IMQA SDK in the React native environment, execute the command below to install the package.

When Using npm Command
// npm install imqa-react-native-agent --save 
When Using yarn Command
yarn add imqa-react-native-agent

2. Installing Gradle plugin

In the “app.gradle” file, add “imqa-mpm-injector” to the “dependencies” block in the "buildscript" followed by “plugin” at the top. This is typically located in “<project_dir>/app/build.gradle”.

The gradle file should be synchronized after updating the file.

app.gradle(project root)
/// Add Build script dependencies 
buildscript { 
    repositories { 
        mavenCentral()
    } 
    
    dependencies {
    // Add dependencies.
        classpath 'io.imqa:imqa-mpm-injector:2.25.6' ... 
    } 
} 
  • java

app.gradle(app module) -> java
...
    dependencies {
    // Add dependencies.
       implementation 'io.imqa:imqa-core:2.27.3'
       implementation 'io.imqa:imqa-mpm-client:2.27.7'
       implementation 'io.imqa:imqa-crash-client:2.27.2'
    } 
} 

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)
    }
  • kotlin

app.gradle(app module) -> kotlin
...
    dependencies {
    // Add dependencies.
       implementation 'io.imqa:imqa-core:2.27.3'
       implementation 'io.imqa:imqa-mpm-client:2.27.7'
       implementation 'io.imqa:imqa-crash-client:2.27.2'
    } 
} 

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)
    }
}
  • java + kotlin

app.gradle(app module) -> java + kotlin
...

    dependencies {
    // Add dependencies.
       implementation 'io.imqa:imqa-core:2.27.3'
       implementation 'io.imqa:imqa-mpm-client:2.27.7'
       implementation 'io.imqa:imqa-crash-client:2.27.2'
    } 
} 

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

3. Adding authority to the Android Manifest

You have to grant Internet authority to upload occurred crash information to AndroidManifest.xml.

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

4. Inserting the IMQA initialization code into the source code

Writing the IMQA start code

The code should be inserted into the application class, not activity.

At this time, insert the copied “Project Key” value into “PROJECT_KEY”.

MyApplication.java
...
@Override
public void onCreate() {
    super.onCreate();
    io.imqa.core.IMQAOption imqaOption = new io.imqa.core.IMQAOption();
    imqaOption.setBuildType(false);
    imqaOption.setUploadPeriod(true);
    imqaOption.setKeepFileAtUploadFail(false);
    imqaOption.setDumpInterval(10000);
    imqaOption.setFileInterval(5);
    imqaOption.setHttpTracing(true);
    imqaOption.setRemoteControl(true);

    io.imqa.mpm.IMQAMpmAgent.getInstance()
        .setOption(imqaOption) // Sets an option to decide the MPM operation method.
        .setContext(this, BuildConfig.FLAVOR) 
        // Initializes the application context. (Insert an empty string if there is no flavor)
        .setProjectKey("PROJECT_KEY") 
        // Sets the project key of the IMQA MPM client.
        .init(); 
        // Initializes and executes the registered option.
    ...
}
...
MyApplication.kt
...
override fun onCreate() {
    super.onCreate()
    val imqaOption : IMQAOption = io.imqa.core.IMQAOption()
    imqaOption.setBuildType(false)
    imqaOption.setUploadPeriod(true)
    imqaOption.setKeepFileAtUploadFail(false)
    imqaOption.setDumpInterval(10000)
    imqaOption.setFileInterval(5)
    imqaOption.setHttpTracing(true)
    imqaOption.setRemoteConfig(true)

    io.imqa.mpm.IMQAMpmAgent.getInstance()
        .setOption(imqaOption) 
        // Sets an option to decide the MPM operation method.
        .setContext(this, BuildConfig.FLAVOR) 
        // Initializes the application context. (Insert an empty string if there is no flavor)
        .setProjectKey("PROJECT_KEY") 
         // Sets the project key of the IMQA MPM client.
        .init(); 
         // Initializes and executes the registered option.
    ...
}
...

MPM Mode Option

You can change the IMQA MPM execution options using parameters or options. Check the execution options in Android MPM Configuration Options.

Shortcut mode

You can initialize IMQA MPM using the shortcut mode.

MyApplication.java
...
override fun onCreate() {
    super.onCreate()

    io.imqa.mpm.IMQAMpmAgent.getInstance()
        .setContext(this, BuildConfig.FLAVOR) // Initializes the application context. (Insert an empty string if there is no flavor)
        .setProjectKey("PROJECT_KEY") // Sets the project key of the IMQA MPM client.
        .init() // Initializes and executes the registered option.
    ...
}
...
MyApplication.kt
...
override fun onCreate() {
    super.onCreate()

    io.imqa.mpm.IMQAMpmAgent.getInstance()
        .setContext(this, BuildConfig.FLAVOR) // Initializes the application context. (Insert an empty string if there is no flavor)
        .setProjectKey("PROJECT_KEY") // Sets the project key of the IMQA MPM client.
        .init() // Initializes and executes the registered option.
    ...
}
...

⚠️HTTPS (API level > 27)

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.

MyApplication.java or MyApplication.kt
...
imqaOption.setServerUrl('https://collector.imqa.io');
...
  1. Forced HTTP request

    You can allow all cleartext HTTP traffic by setting this flag.

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

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:

  1. Setting the MPM Mode Option You can set whether to use Zstd in the settings when inserting the IMQA startup code.

MyApplication.java or MyApplication.kt
...
imqaOption.setCompressZstd(true);
...
  1. Add Zstd Library In the “app.gradle” file, add the “zstd-jni” aar library to the “dependencies” block in “buildscript”.

app.gradle(app module)
...
    dependencies {
    // Add dependencies.
      ...
       implementation 'com.github.luben:zstd-jni:1.5.2-3@aar'
       ...
    }
} 

5. ⚠️Issues in the current version

  1. ASM Conflict may occur with the library using ASM.

  2. APK Repackaging Source line information disappears while repackaging the APK. The auto-insert function should be executed during compilation, in order to include line information.

  3. Collecting library information The auto-insert function is not executed in the class file added to the library. The auto-insert function should be executed while repackaging the API, in order to collect information on what is executed in the library.

6. Settings required for the installation-type

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

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

    /*
     * Default value: 'https://collector.imqa.io'
     * Sets the MPM server URL.
     * String: Server information
     */
    imqaOption.setServerUrl('https://(IPAddress)');

    io.imqa.mpm.IMQAMpmAgent.getInstance()
        .setOption(imqaOption) // Sets the option to decide the MPM operation method.
        .setContext(this, BuildConfig.FLAVOR) // Initializes the application context. (Insert an empty string if there is no flavor)
        .setProjectKey("PROJECT_KEY") // Sets the project key of the IMQA MPM client.
        .init() // Initializes and executes the registered option.
    ...
}
...

Last updated