Getting Started
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.
Note: The BlueStack Unity plugin dependencies are listed in Packages/com.azerion.bluestack/Editor/BlueStackDependencies.xml file.
- Android
- iOS
1. Add repository dependencies
- Unity version 2022 or newer
- Unity version 2021 or older
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.
Add the following repo dependencies.
dependencyResolutionManagement {
...
repositories {
...
google()
mavenCentral()
maven {
url 'https://packagecloud.io/smartadserver/android/maven2'
}
...
}
...
}
Open the file baseProjectTemplate.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 Base Gradle Template
gradle option.
Add the following repo dependencies.
allprojects {
...
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.
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**}
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")
}
...
}
<iosPods>
<iosPod name="BlueStack-SDK" version="4.2.7" bitcodeEnabled="false"
addToAllTargets="false"/>
</iosPods>
- BlueStack iOS framework needs to have minimum iOS version
12.2
. - Go to the player settings and set the
Target minimum iOS Version
greater than or equal to12.2
. - In the Unity editor, select
File > Build Settings > Build
. The Unity External Dependency Manager library will copy the declared dependencies fromBlueStackDependencies.xml
into thePodfile
file to theUnityFramework
target of your Unity-iPhone app.
source 'https://cdn.cocoapods.org/'
platform :ios, '12.2'
target 'UnityFramework' do
pod 'BlueStack-SDK', '4.4.0'
end
target 'Unity-iPhone' do
end
- It is recommended to remove
:linkage => :static
from thePodfile
file or uncheckLink frameworks statically
from iOS Resolver Settings of EDM4U. - If EDM4U failed to resolve the dependencies that are in
Podfile
then you need to manually resolve those dependencies by executingpod install --repo-update
from the terminal.
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.
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.
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.
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.