Aller au contenu principal

Getting Started

info

This section explains how to getting started BlueStack Unity Plugin. It guides you through the process of adding the BlueStack Unity Plugin to your project. After following this section you’re being able to getting started with the more advanced features of the BlueStack Unity Plugin.

Prerequisites

  • Use Unity 2020 or higher
  • Android
    • Minimum Android API level of 21 or higher
    • Target Android API level 31 or higher
  • iOS
    • Xcode 15.3 or higher
    • iOS 12.2 or higher
    • CocoaPods

Import the package

Follow the steps listed below to ensure your project includes the BlueStack SDK.

  • Add scoped registries in Edit -> Project Settings -> Package Manager -> Add Scoped Registry

  • Add npm registry for BlueStack

    Name: Azerion
    URL: http://registry.npmjs.com
    Scope(s): com.azerion.bluestack
  • BlueStack Unity package has a indirect dependency of EDM4U which need to be resolved using UPM.

    Name: package.openupm.com
    URL: https://package.openupm.com
    Scope(s): com.google.external-dependency-manager
  • Update Packages/manifest.json

    {
    "dependencies": {
    "com.azerion.bluestack": "3.0.0"
    }
    }

Manage Dependencies

BlueStack Unity plugin maintains native BlueStack SDK version compatibility. To accomplish this BlueStack Unity plugin is distributed with the EDM4U. It provides Unity plugins the ability to declare dependencies(Android specific libraries (e.g., AARs) or iOS CocoaPods), which are then automatically resolved and copied into your Unity project.

info

Note: The BlueStack Unity plugin dependencies are listed in Packages/com.azerion.bluestack/Editor/BlueStackDependencies.xml file.

1. Add repository dependencies

Open the file settingsTemplate.gradle file in Assets/Plugins/Android. If you don't have such a file, go to Project Settings > Player > Publishing Settings and enable the Custom Gradle Settings Template gradle option.

custom_gradle_settings_template

Add the following repo dependencies.

    dependencyResolutionManagement {
...
repositories {
...
google()
mavenCentral()
maven {
url 'https://packagecloud.io/smartadserver/android/maven2'
}
...
}
...
}

2. Enable the Custom Main Gradle Template

Add mainTemplate.gradle. Go to Project Settings > Player > Publishing Settings and enable the mainTemplate gradle option.

custom_main_gradle_template

3. Resolve Android Dependencies

In the Unity editor, select Assets > External Dependency Manager > Android Resolver > Resolve. T he Unity External Dependency Manager library will copy the declared dependencies from BlueStackDependencies.xml into the Assets/Plugins/Android/mainTemplate.gradle file of your Unity project.

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
implementation 'com.azerion:bluestack-sdk-core:4.4.0'
// Android Resolver Dependencies End
**DEPS**}

attention

If EDM4 doesn't copy the dependencies into mainTemplate.gradle then you can manually add those dependencies or force EDM4 via Assets > External Dependency Manager > Android Resolver > Force Resolve

Known android build issues and solution

  • Kotlin module issue
More than one file was found with OS independent path 'META-INF/annotation-experimental_release.kotlin_module'

Please add the following config into launcherTemplate.gradle

android {
...
packagingOptions {
exclude("META-INF/*.kotlin_module")
}
...
}

Initialize the BlueStack SDK

Before loading ads, you need to initialize the BlueStack SDK by calling BlueStackAds.Initialize() This needs to be done only once, ideally at app launch. Initialize method has two callbacks; One to get SDK initialization status and another (optional) to get Ad adapters Initialization status.

info

Note: You will have to register your app in BlueStack console to get an appId for your app.

Here's an example of how to call Initialize() within the Start() method of a script attached to a GameObject:

...
using Azerion.BlueStack.API;
using Azerion.BlueStack.API.Banner;
using Azerion.BlueStack.API.Rewarded;

public class BlueStackAdController : MonoBehaviour
{
public void Start()
{
Settings settings = new Settings(isDebugModeEnabled: true);
// Initialize the BlueStack SDK.
BlueStackAds.Initialize(appId, settings, HandleSDKInitCompleteAction, HandleAdaptersInitCompleteAction);
}

// HandleSDKInitCompleteAction callback is called once SDK Initialization is complete.
private void HandleSDKInitCompleteAction(SDKInitializationStatus sdkInitializationStatus)
{
bool isSuccess = sdkInitializationStatus.IsSuccess;
string description = sdkInitializationStatus.Description;

if (isSuccess)
{
Debug.Log("BlueStack SDK initialization success: " + description);
}
else
{
Debug.Log("BlueStack SDK initialization failed: " + description);
}
}

// HandleAdaptersInitCompleteAction callback is called when Ad adapters Initialization is complete.
private void HandleAdaptersInitCompleteAction(AdaptersInitializationStatus adaptersInitializationStatus)
{
foreach (KeyValuePair<string, AdapterStatus> adapterStateEntry in adaptersInitializationStatus.GetAdapterStatusMap())
{
Debug.Log("Adapter Name: " + adapterStateEntry.Value.Name + ", " +
"Adapter State: " + adapterStateEntry.Value.InitializationState + ", " +
"Adapter Description: " + adapterStateEntry.Value.Description);
}
}

}

Mediation Ad Network

BlueStack SDK mediation feature enable you to server ads from multiple sources including Madvertise and third-party ad networks.

info

To load ads from third party ad networks, you will have to first configure each ad network for your app on BlueStack console.

Settings

BlueStack setings allows you to configure mediation networks. To open the setings, select Azerion > BlueStack > Settings from the menu.

Configure AdMob App ID

  • You can insert AdMob App ID here for both iOS and Android platforms.

Select Mediation Networks

  • You can choose your prefered mediation networks from the list. Check the Mediation Partners documentation for more details.

editor-settings

attention

You need to resolve or force resolve Android dependencies via EDM4 Assets > External Dependency Manager > Android Resolver > Force Resolve every time you add/remove any mediation networks from the Settings.