This guide provides step-by-step instructions to integrate MSEC SDK into your Unity project, including package installation, SDK initialization, and event handling.
Note
If you may encounter any of the errors listed below, you can follow the corresponding solutions to resolve them.
For any other unexpected issues during the integration process, feel free to contact us for further assistance.:
Case 1: “CommandInvokationFailure: Gradle build failed”
Cause: Package conflicts or corrupted build cache.
Solution:
Remove unnecessary packages via
.Delete the
[Project_Name]/Library
folder. Unity will regenerate it upon reopening.Verify build settings:
, select Android, click Switch Platform.Case 2: Duplicate library copy error (.so file duplication)
Cause: Unity flags duplicate
.so
files during the build process.Solution:
Open the file:
Assets/Plugins/Android/launcherTemplate.gradle
.Locate the android { … } block. Add the following snippet inside the android {} block :
packaging { pickFirst 'lib/x86/libc++_shared.so' pickFirst 'lib/x86_64/libc++_shared.so' pickFirst 'lib/armeabi-v7a/libc++_shared.so' pickFirst 'lib/arm64-v8a/libc++_shared.so' }
After applying the fixes, rebuild the project and check for any remaining errors.
Import External Dependency Manager for Unity (EDM4U)
Open Unity Hub.
Navigate to: Window → Package Manager → Add package from git URL….
Copy and paste the url below,click Add to import the package:
https://github.com/googlesamples/unity-jar-resolver.git?path=upmEDM4U is a plugin that manages dependencies for Unity projects when using third-party services like Firebase, AdMob, or MSEC SDK.
Import MSEC SDK For Unity
Follow the same steps as above, but use the MSEC SDK For Unity Git URL or download asset from Unity Asset Store
Resolve Dependencies
Open Unity.
With Android platform: navigate to Assets → External Dependency Manager → Android Resolver → Resolve.
With iOS platform: Install CocoaPods Dependencies
Open Terminal and navigate to the project directory:
cd /path/to/your/projectInstall the required dependencies:
pod installThis command will install MSECSDK and generate an .xcworkspace file.
If your Xcode version is lower than 14.2, you need to modify the declaration of the pod MsecSdk in the Podfile to avoid build issues. Update the Podfile as follows:
1source 'https://github.com/msecsys-dev/msec-sdks.git' 2source 'https://github.com/CocoaPods/Specs' 3source 'https://cdn.cocoapods.org/' 4 5platform :ios, '13.0' 6 7target 'UnityFramework' do 8 pod 'MsecDynamicSdk', '~>1.0.1', :modular_headers => true 9end 10 11target 'Unity-iPhone' do 12end 13 14use_frameworks! :linkage => :staticIf necessary, click Force Resolve to refresh dependencies.
To use the MSEC SDK in your Unity project, you first need to import the required namespace.
1using MsecUnitySdk;
Callback Methods
OnViolationDetected
1public void OnViolationDetected(ViolationInfo violationInfo)
2{
3 Debug.Log("Violation detected: " + violationInfo.Name + " " + violationInfo.Category + " " + violationInfo.Code);
4}
Triggered when the SDK detects a security violation. This method provides: - Name of the violation - Violation category - Violation code
OnInitializationCompleted
1public void OnInitializationCompleted(InitializationStatus InitStatus)
2{
3 Debug.Log("Initialization completed with status: " + InitStatus.Success +" "+InitStatus.Timestamp+" "+InitStatus.Otp);
4 if(InitStatus.Success){
5 Debug.Log("OTP call from user:" + MsecSdk.GetOTPCode(InitStatus.Timestamp));
6 }
7 Debug.Log("Mitm status code: " + MsecSdk.VerifyDomainCertificate("vnexpress.net", 443));
8}
Called after the SDK finishes initialization.
Provides:
Initialization status (success/failure)
Timestamp and OTP code for security
MITM (Man-in-the-Middle) check result using domain certificate verification
OnPerformanceDataReported
1public void OnPerformanceDataReported(PerformanceData performanceData)
2{
3 Debug.Log("Performance data reported: " + performanceData.CpuUsage + " " + performanceData.MemoryUsage + " " + performanceData.Fps + " " + performanceData.Threads + " " + performanceData.Timestamp);
4}
Reports real-time performance statistics, including: - CPU usage - Memory usage - FPS (Frames Per Second) - Active thread count - Timestamp of data collection
The following script demonstrates how to initialize and use Msec SDK in Unity.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using MsecUnitySdk;
5using System;
6using System.Runtime.InteropServices;
7using MsecUnitySdk;
8
9namespace MsecSdkTest
10{
11 public class TestMsecSdkForUnity : MonoBehaviour, IMsecSdkListener
12 {
13 // Start is called before the first frame update
14 void Start()
15 {
16 Application.targetFrameRate = 1;
17 try
18 {
19 MsecSdkConfig config = new MsecSdkConfig()
20 {
21 Debug = true,
22 AppVersion = Application.version,
23 };
24 MsecSdk.Init(this, config);
25 }
26 catch (System.Exception e)
27 {
28 Debug.LogError("Error initializing MsecSdk: " + e.Message);
29 }
30 }
31
32 void Update()
33 {
34
35 }
36
37 public void OnViolationDetected(ViolationInfo violationInfo)
38 {
39 Debug.Log("Violation detected: " + violationInfo.Name + " " + violationInfo.Category + " " + violationInfo.Code);
40 }
41 public void OnInitializationCompleted(InitializationStatus initStatus)
42 {
43 Debug.Log("Initialization completed with status: " + initStatus.Success + " " + initStatus.Timestamp + " " + initStatus.Otp);
44 if(initStatus.Success)
45 {
46 Debug.Log("OTP call from user:" + MsecSdk.GetOTPCode(initStatus.Timestamp));
47 }
48 Debug.Log("Mitm status code: " + MsecSdk.VerifyDomainCertificate("google.com", 443));
49 }
50
51 public void OnPerformanceDataReported(PerformanceData performanceData)
52 {
53 Debug.Log("Performance data reported: " + performanceData.CpuUsage + " " + performanceData.MemoryUsage + " " + performanceData.Fps + " " + performanceData.Threads + " " + performanceData.Timestamp);
54 }
55 }
56}
Similar to the Android setup, install the necessary packages and initialize the code. If you have already completed the Android version setup, you can skip steps 1.1, 1.2, and 1.3 in Andoid.
Open Unity and go to File —> Build Settings.
Select Android as the target platform.
Click Switch Platform.
Click Build (ensure it’s a clean build).
Build and run your games
Open Unity and go to File —> Build Settings.
Select iOS as the target platform.
Click Switch Platform.
Click Build (ensure it’s a clean build).
Unity will generate an iOS project folder.
Open the generated .xcworkspace file using Xcode.
Select the Unity-iPhone target.
Go to the General tab.
Under Frameworks, Libraries, and Embedded Content, add MsecDynamic.xcframework.
The MsecDynamic.xcframework is usually found in the Pods directory of your project.
Build and run your games