- 20 Nov 2024
- 2 Minutes To Read
-
Print
-
DarkLight
-
PDF
Integrate Whatfix Mobile SDK with MAUI (Android)
- Updated On 20 Nov 2024
- 2 Minutes To Read
-
Print
-
DarkLight
-
PDF
To create Whatfix Mobile in-app experiences on Android apps built using MAUI (Multi-platform App UI), you need to first set up Whatfix Mobile.
Pre-requisite
In some cases, MAUI applications require tagging specific elements with an AutomationId for precise screen element identification. This approach is also recommended for automation testing in MAUI applications.
Use the following code snippet for tagging Android MAUI views:
<Button x:Name="randomizeButton"
Text="Randomize"
AutomationId="randomize_button_id"
Clicked="OnRandomizeButtonClicked"
HorizontalOptions="Center"
VerticalOptions="Center" />
Integration steps for MAUI Android
Use the following steps to integrate the Whatfix Mobile SDK in your MAUI Android project:
Ensure that you complete both the steps, to create and test the in-app experience in your integrated build.
Step 1: Integrate Whatfix Mobile SDK
a. Add the Whatfix Mobile MAUI SDK dependency
Add the Whatfix Mobile MAUI Library package from nuget.
Add the WhatfixMAUI.Android package from nuget to the Packages in your Android specific project using the following command:
dotnet add package WhatfixMAUI.Android --version 2.0.4
b. Start the Whatfix Mobile SDK
Start the Whatfix Mobile SDK using the following code snippet:
using IS.Leap.Android.Aui;
namespace yourAppNamespace
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
Leap.Start("<YOUR_API_KEY>");
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Step 2: Enable the Creator Mode in your app
To create in-app experiences in the Whatfix Mobile Studio, you have to enable the Creator mode in your app. This is done by integrating the Whatfix Mobile Creator SDK.
a. Add dependencies
Your title goes here
The Whatfix Mobile Creator Plugin must be removed before the app goes live on the Play Store.
While both Whatfix Mobile Creator SDK and Whatfix Mobile SDK need to be integrated in the development and testing versions, the production version should only have the Whatfix Mobile SDK.
Add the Whatfix Mobile MAUI Creator package from nuget.
Add WhatfixMAUI.Android.Creator package from nuget to the Packages in your Android specific project using the following command:
dotnet add package WhatfixMAUI.Android.Creator --version 2.0.4
b. Start the Whatfix Mobile Creator SDK
Start the Whatfix Mobile Creator SDK using the following code snippet:
using IS.Leap.Android.Creator;
namespace yourAppNamespace
{
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
LeapCreator.Start("<YOUR_API_KEY>");
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
}
Proguard Rules
If you are using Proguard for your builds, use the following rules in your proguard-rules.pro file:
-dontwarn is.leap.android.**
-keep class is.leap.android.** {*;}
If you are using Android Gradle Plugin (AGP) version 8.0 or newer, it may be necessary to include specific OkHttp rules in your proguard-rules.pro file. This step needs to be done to ensure the proper execution of release builds, as the LeapCreator SDK relies on the OkHttp library. The required rules are as following:
#For Okhttp
-dontwarn okhttp3.internal.platform.**
-dontwarn org.conscrypt.**
-dontwarn org.bouncycastle.**
-dontwarn org.openjsse.**
For more information, see Okhttp R8 / ProGuard.
After integrating the code, you can start creating your in-app experience using Whatfix Mobile.