Configure the MobilePush SDK Flutter Plugin for Android Apps
After you install and configure the MobilePush SDK Flutter plugin, configure the plugin to enable push support for the Android platform.
The implementation steps can vary depending on your app and the Flutter version it uses.
To add the MobilePush SDK repository to your project, add this code to your android/build.gradle file.
To add the marketingcloudsdk dependency to your project, add this code to your android/app/build.gradle file.
In your app’s build.gradle file, set the SDK version parameters to the versions listed in this table.
| Parameter | Version |
|---|---|
compileSdk or compileSdkVersion | 35 |
minSdkVersion | 23 |
Ensure the org.jetbrains.kotlin.android or org.jetbrains.kotlin:kotlin-gradle-plugin plugin is version 1.9.10 or later.
Depending on your Flutter implementation, the location for specifying the Kotlin version can differ. You can specify the Kotlin version in either android/build.gradle or android/settings.gradle.
To enable push support for the Android platform, provide your Firebase Cloud Messaging (FCM) credentials by including the google-services.json file in your config.xml file.
-
Download the
google-services.jsonfile from your application’s Firebase console and place it in your project’sandroid/appdirectory -
To include the Google Services plugin, add this code to your
android/settings.gradlefile.If
pluginManagementisn’t present in yoursettings.gradle, add this dependency inandroid/build.gradleunder thebuildscriptsection. If the Gradle file doesn't have abuildscriptsection, add it. -
To apply the plugin, add this code to your
android/app/build.gradlefile.This step can vary depending on your implementation.
If the
pluginssection doesn’t exist in yourandroid/app/build.gradlefile, add this code to the end of the file.
If MainApplication.kt isn’t present in your app, create it by extending the FlutterApplication class. Additionally, update AndroidManifest.xml.
Update MainApplication.kt in your app.
To customize push functionality, see Customize Push Notification Functionality for Android Apps.
To implement the Carousel and Button actions features introduced in Android SDK version 9.0.0, see Configure Button and Carousel Actions.
Update AndroidManifest.xml to declare the notification permission.
The SDK doesn’t automatically present URLs from these sources.
- CloudPages URLs from push notifications
- OpenDirect URLs from push notifications
- Action URLs from in-app messages
To handle URLs from push notifications, follow these steps.
Navigate to MainApplication.kt and update setNotificationCustomizationOptions to include the code in this example.
-
Open
MainApplication.ktin an editor. -
In the
setNotificationCustomizationOptionssection, add theseimportstatements. -
Update
setNotificationCustomizationOptionsinMarketingCloudConfig. -
Implement these methods in
MainApplication.kt.
To handle URLs from in-app messages, set the setUrlHandler in MarketingCloudConfig as shown in this example.
Additionally, review the additional documentation on URL Handling for Android.
If you encounter errors related to Java sealed classes or dexing, add the r8 dependency to your app. For more information about this error, see Google’s IssueTracker.
To add the r8 dependency, update your app’s settings.gradle file.
If you don’t have pluginManagement in your settings.gradle file, update the buildscript.dependencies section of the android/build.gradle file.