Flutter SDK Access
The APM Flutter SDK is based on the native APM SDK. It can collect and report app startup performance, crashes, freezes, errors, network requests, device information, and custom statistics.
Prerequisites
Before using the SDK, you need to register a HUAWEI ID and create an iOS app and an Android app on the App Monitoring page.
Transport Protocol
HTTPS.
Version Updates
| Version | Description | System |
|---|---|---|
| 1.0.0 |
| Flutter 3.35.6+, Dart 3.9.2+, iOS 15+, Android 7+, Gradle 8.11.1+, AGP: 8.9.1+, KGP 2.1.0+, JDK 17+, APM iOS SDK 2.1.0+, and APM SDK 2.1.0+ |
Procedure
- Connect the SDK.
- Add the APM Flutter SDK to flutter_app/pubspec.yaml. The code is as follows:
dependencies: ... apm_flutter_plugin: 1.0.0
- Add the APM Android SDK to flutter_app/android/build.gradle.kts. The code is as follows:
buildscript { repositories { google() mavenCentral() } ... dependencies { ... classpath("io.github.apm-sdk:apm-sdk-plugin:2.1.0") } } - Add the APM Android SDK to flutter_app/android/app/build.gradle.kts. The code is as follows:
plugins { ... id("com.cloud.apm.plugin") } android { ... dependencies { ... implementation("io.github.apm-sdk:apm-sdk-android:2.1.0") } } - Add the APM iOS SDK to flutter_app/ios/Podfile. The code is as follows:
pod 'APMSDK', '2.1.0'
- Add the APM Flutter SDK to flutter_app/pubspec.yaml. The code is as follows:
- Add a configuration file.
During the creation of a mobile app, a configuration file named apm-sdk-config.json will be generated. The following table lists the parameters.
Parameter
Mandatory
Default Value
Description
appId
Yes
-
Mobile app ID.
authorization
Yes
-
Used for app authentication.
region
Yes
-
Region where APM is deployed. Currently, ap-southeast-3 is supported.
uid
No
-
Custom ID.
tag
No
-
Custom tag. Use commas (,) to separate multiple tags.
url
No
-
Public domain name for reporting data to APM.
networkWhiteList
No
-
Network monitoring whitelist.
cacheThreshold
No
200
When the number of records stored in the local database reaches this threshold, an alarm is reported. Value range: 30 to 1,000.
timeInterval
No
60s
Interval for triggering reporting. Value range: 60 to 1,800, in seconds.
reportBackground
No
true
Whether to report logs upon app backend switching.
reportLaunch
No
false
Whether to report logs upon app startups.
enableNetwork
No
false
Whether to enable network collection.
enableCrash
No
false
Whether to enable crash collection.
enableLaunch
No
false
Whether to enable startup collection.
enableANR
No
false
Whether to enable freeze collection.
enableError
No
false
Whether to enable error collection.
enableDevice
No
false
Whether to enable device collection.
enableEvent
No
false
Whether to enable custom statistics reporting.
traceType
No
apm
Whether to enable open tracing. If this function is enabled, OpenTelemetry will be used. If this function is disabled, APM tracing will be used.
logLevel
No
off
Debug log level. Options: debug, info, warn, error, and off.
samplingRate
No
1.0
Sampling rate. Range: 0–1.0.
- Add a configuration file to the iOS app.
- Add a configuration file to the Android app.
- Download the configuration file and drag it to the root directory of the app module.

- Download the configuration file and drag it to the root directory of the app module.
- Start the SDK.
- Starting the APM Flutter SDK
import 'package:apm_flutter_plugin/apm_flutter_plugin.dart'; void main() { APMFlutterSDK.runApp(() async { .....// (Optional) Set a custom ID. APMFlutterSDK.setUid("custom ID"); // (Optional) Set custom tags. APMFlutterSDK.addTag ("Custom tag 1,Custom tag 2,Custom tag 3"); // Run the app..... return runApp(const MyApp()); }); } - Starting the APM Android SDK
import com.cloud.apm.APMSDK; import com.cloud.apm_flutter_plugin.APMFlutterPlugin; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); // Start the APM SDK. var extraConfig = new HashMap<String, Object>(); extraConfig.put("crossPlatformUA", APMFlutterPlugin.crossPlatformUA()); APMSDK.start(this, extraConfig); } }
- Starting the APM Flutter SDK
- Configure custom statistics reporting.
Method
Description
static Future<void> event(String key, Object value)
key: event name. Max.: 2,048 characters. value: event content, which can be a string, list, map, or number. Max.: 30,720 characters.
Sample code:
// Event statistics APMFlutterSDK.event("User Information", {"name": "XXX"}); APMFlutterSDK.event("Error Description", "The request timed out."); APMFlutterSDK.event("Call Stack", ["0x0000000101ee9c6c", "0x0000600000e61d80"]); // Numeric statistics APMFlutterSDK.event("Custom Load Time", 0.238); APMFlutterSDK.event("Purchase Statistics", 1);
Obfuscation Configuration
Add the following code to the obfuscation configuration file proguard-rules.pro:
# Retain the source file name and source code line number as required.
-keepattributes LineNumberTable, SourceFile
# Prevent the APM SDK from being obfuscated.
-keep class com.cloud.apm_flutter_plugin.** {*;}
-keep class com.cloud.apm.**{*;}
# Use the following configuration as required.
-keepclasseswithmembers class okhttp3.**{*;} # Use okhttp3&okhttp.
-dontwarn okhttp3.** # okhttp3&okhttp4 is not used.
-keepclasseswithmembers class com.squareup.okhttp.**{*;} # Use okhttp2.
-dontwarn com.squareup.okhttp.** # okhttp2 is not used. ASM Version Configuration
If the following compilation errors occur:
java.lang.UnsupportedOperationException: NestMember requires ASM7
at org.objectweb.asm.ClassVisitor.visitNestMember(ClassVisitor.java:265)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:697)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)
at com.cloud.apm.plugin.tasks.trace.methodTrace.MethodTracer.innerTraceMethodFromJar(MethodTracer.kt:184)
at com.cloud.apm.plugin.tasks.trace.methodTrace.MethodTracer.traceMethodFromJar$lambda-4$lambda-3(MethodTracer.kt:89) Add the following code to flutter_app/android/gradle.properties:
com.cloud.apm.asmApi=ASM7
Data Reporting Policy
The SDK supports four reporting policies: threshold-based reporting, scheduled reporting, reporting upon app backend switching, and reporting upon app startups. Configure cacheThreshold, timeInterval, reportBackground, and reportLaunch based on scenarios.
Enabling the Debug Log Function
Enable the debug log function if needed. Then you can monitor real-time SDK running through the console, check logs, and make adjustments. The log level can be debug, info, warn, error, or off (disabled).
Disable the debug log function before bringing an app online. That is, set the log level to off.
Example: Set the log level in the apm-sdk-config.json configuration file.
{
"logLevel": "debug"
} Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot


