If you add IMQA MPM 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.
Min SDK : 14
Target SDK : 33
Build Tool : ~7.2
Gradle Wrapper : ~ 7.1.3
Kotlin : ~ 1.3.21
Android Studio : ~ Giraffe
Please install Crash SDK after creating an Android project at the IMQA project page and receiving the project key.
In the “app.gradle” file, add “imqa-mpm-injector” to the ”dependencies” block in “buildscript” and add “plugin” to the top. Generally, it can be found in “<project_dir> /app/build.gradle”.
If the app project structure is not the basic Android Project structure, quick build using Gradle's daemon is set, or SDK is not applied properly (native UI loading time (Webview X), network response time, etc. are not collected. Please apply by referring to 'Installing MPM SDK > Gradle Plugin Detailed setting'.
The gradle file should be synchronized after updating the file.
...
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
It can be applied when the app project structure is not the basic Android Project structure, when quick build using gradle's daemon is set up, when SDK application does not work properly (native UI loading time (Webview X), or when network response time, etc. cannot be collected.
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.
java
app.gradle(app module) -> 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.injector.IMQABuildOption imqaBuildOption =new io.imqa.injector.IMQABuildOption();imqaBuildOption.setProjectHomePath("Path of project") // Path of project (ex:/user/workspace/project1)imqaBuildOption.setAndroidManifestPath("Path to built manifest file")// Path to built manifest file (ex:/user/workspace/project1/app/build/intermediates/merged_manifest/debug/AndroidManifest.xml)
imqaBuildOption.setJavaBuildPath("")// Add only java project (ex:/user/workspace/project1/app/build/intermediates/javac/debug/classes) io.imqa.IMQAPlugin imqaPlugin =new io.imqa.IMQAPlugin()imqaPlugin.init(project, imqaBuildOption)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), imqaBuildOption ).execute(task) }}
kotlin
app.gradle(app module) -> 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.injector.IMQABuildOption imqaBuildOption = new io.imqa.injector.IMQABuildOption();imqaBuildOption.setProjectHomePath("Path of project") // Path of project (ex:/user/workspace/project1)imqaBuildOption.setAndroidManifestPath("Path to built manifest file")// Path to built manifest file (ex:/user/workspace/project1/app/build/intermediates/merged_manifest/debug/AndroidManifest.xml)
imqaBuildOption.setKotlinBuildPath("")// Add only kotlin project (ex:/user/workspace/project1/app/build/tmp/kotlin-classes/debug) io.imqa.IMQAPlugin imqaPlugin = new io.imqa.IMQAPlugin()imqaPlugin.init(project, imqaBuildOption)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), imqaBuildOption ).execute(task) }}
... dependencies {// 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") } } val imqaBuildOption:io.imqa.injector.IMQABuildOption=io.imqa.injector.IMQABuildOption();imqaBuildOption.projectHomePath=""// Path of the project (ex:/user/workspace/project1)imqaBuildOption.javaBuildPath = "" // Add only java project (ex:/user/workspace/project1/app/build/intermediates/javac/debug/classes)
imqaBuildOption.androidManifestPath = "" // Path to built manifest file (ex:/user/workspace/project1/app/build/intermediates/merged_manifest/debug/AndroidManifest.xml)
val imqaPlugin:io.imqa.IMQAPlugin=io.imqa.IMQAPlugin()imqaPlugin.init(project,imqaBuildOption)io.imqa.injector.GJavacAction(project.name)android.applicationVariants.all { val variant =this val javaCompileTask =variant.javaCompileProvider?.get() javaCompileTask?.doLast { val task =thisio.imqa.injector.CompileAction(io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.javacClasses,project.name,io.imqa.injector.GJavacAction.convertBuildType(variant.buildType),io.imqa.injector.GJavacAction.makeFlavor(variant.buildType.name, variant), imqaBuildOption ).execute(task) }}
kotlin
app.gradle(app module) -> 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") } } val imqaBuildOption: io.imqa.injector.IMQABuildOption = io.imqa.injector.IMQABuildOption();imqaBuildOption.projectHomePath =""// Path of the project (ex:/user/workspace/project1)imqaBuildOption.kotlinBuildPath =""// Add only kotlin project(ex:/user/workspace/project1/app/build/tmp/kotlin-classes/debug) imqaBuildOption.androidManifestPath = "" // Path to built manifest file (ex:/user/workspace/project1/app/build/intermediates/merged_manifest/debug/AndroidManifest.xml)
val imqaPlugin: io.imqa.IMQAPlugin = io.imqa.IMQAPlugin()imqaPlugin.init(project,imqaBuildOption)io.imqa.injector.GJavacAction(project.name)android.applicationVariants.all {val variant =thisval javaCompileTask = variant.javaCompileProvider?.get() javaCompileTask?.doLast {val task =this io.imqa.injector.CompileAction( io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.kotlin, project.name, io.imqa.injector.GJavacAction.convertBuildType(variant.buildType), io.imqa.injector.GJavacAction.makeFlavor(variant.buildType.name, variant), imqaBuildOption ).execute(task) }}
java + kotlin
app.gradle(app module) -> java + 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") } } val imqaBuildOption:io.imqa.injector.IMQABuildOption=io.imqa.injector.IMQABuildOption();imqaBuildOption.projectHomePath=""// Path of project (ex:/user/workspace/project1)imqaBuildOption.javaBuildPath = "" // Add only java project (ex:/user/workspace/project1/app/build/intermediates/javac/debug/classes)
imqaBuildOption.kotlinBuildPath=""// Add only kotlin project (ex:/user/workspace/project1/app/build/tmp/kotlin-classes/debug) imqaBuildOption.androidManifestPath = "" // Path to built manifest file (ex:/user/workspace/project1/app/build/intermediates/merged_manifest/debug/AndroidManifest.xml)
val imqaPlugin:io.imqa.IMQAPlugin=io.imqa.IMQAPlugin()imqaPlugin.init(project,imqaBuildOption)io.imqa.injector.GJavacAction(project.name)android.applicationVariants.all { val variant =this val javaCompileTask =variant.javaCompileProvider?.get() javaCompileTask?.doLast { val task =thisio.imqa.injector.CompileAction(io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.kotlin,project.name,io.imqa.injector.GJavacAction.convertBuildType(variant.buildType),io.imqa.injector.GJavacAction.makeFlavor(variant.buildType.name, variant), imqaBuildOption ).execute(task)io.imqa.injector.CompileAction(io.imqa.injector.util.BuildOption.BUILD_LOCATION_TYPE.javacClasses,project.name,io.imqa.injector.GJavacAction.convertBuildType(variant.buildType),io.imqa.injector.GJavacAction.makeFlavor(variant.buildType.name, variant), imqaBuildOption ).execute(task) }}
3. Adding authority to the Android Manifest
You have to grant Internet authority to upload occurred crash information to AndroidManifest.xml.
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
...@OverridepublicvoidonCreate() { 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);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
...overridefunonCreate() {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) 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
...overridefunonCreate() {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:
Authenticated HTTPS request
Request authenticated HTTPS to the IMQA server to collect the data normally.
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: (* Only available in paid plan.)
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);
...
Add Zstd Library
In the “app.gradle” file, add the “zstd-jni” aar library to the “dependencies” block in “buildscript”.
Source line information disappears while repackaging the APK. The auto-insert function should be executed during compilation, in order to include line information.
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
...@OverridepublicvoidonCreate() { 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) // AInitializes 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....}...