Aller au contenu principal

Android Migration Guide — BlueStack SDK v5 to v6

· 6 minutes de lecture
Md. Mustafizur Rahman
Md. Mustafizur Rahman
BlueStack SDK Team

This guide covers the breaking changes introduced in BlueStack SDK v6.0.0 for Android and explains how to update your existing v5 integration.

Overview

BlueStack SDK v6 introduces an update that removes the BlueStack and MNG prefixes from all public API classes and constants. The underlying functionality remains the same — only the names have changed. This makes the SDK more neutral and easier to integrate across different publishing environments.

SDK Initialization

The main entry point for initializing the SDK has been renamed from BlueStack to MobileAds.

Before (v5)

import com.azerion.bluestack.BlueStack;
import com.azerion.bluestack.initialization.InitializationListener;
import com.azerion.bluestack.initialization.InitializationStatus;

class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

BlueStack.INSTANCE.initialize(this, "YOUR_APP_ID", initializationStatus -> {
initializationStatus.getAdapterStatusMap().forEach((adNetworkName, adapterStatus) ->
Log.d(TAG, "name: " + adapterStatus.getName() + ", state: " + adapterStatus.getState())
);
});
}
}

After (v6)

import com.azerion.bluestack.MobileAds;
import com.azerion.bluestack.initialization.InitializationListener;
import com.azerion.bluestack.initialization.SDKInitializationStatus;

class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MobileAds.INSTANCE.initialize(this, "YOUR_APP_ID", initializationStatus -> {
initializationStatus.getMediationAdapterStatusMap().forEach((adNetworkName, adapterStatus) ->
Log.d(TAG, "name: " + adapterStatus.getName() + ", state: " + adapterStatus.getState())
);
});
}
}

Privacy Settings

The privacy settings class has been renamed from BlueStackPrivacySettings to PrivacySettings.

Before (v5)

BlueStackPrivacySettings.setIsAgeRestrictedUser(true, context);
BlueStackPrivacySettings.setIsUserOptOut(true, context);

After (v6)

PrivacySettings.setIsAgeRestrictedUser(true, context);
PrivacySettings.setIsUserOptOut(true, context);

Error Handling

The error class AdError and all error constant names remain unchanged in v6. All existing error constants from v5 work exactly the same way in v6.

Error Constants (Unchanged)

Error ConstantError CodeDescription
AdError.WRONG_PLACEMENT_ERROR0Invalid placement ID
AdError.NO_INTERNET_ERROR1No internet connection
AdError.SDK_UNINITIALIZED_ERROR2SDK not initialized
AdError.CAPPED_REQUEST_ERROR3Request limit reached
AdError.LOCKED_PLACEMENT_ERROR4Placement locked by another factory
AdError.BUSY_FACTORY_ERROR5Factory is busy
AdError.NO_AD_ERROR7No ad available
AdError.INTERSTITIAL_COOLDOWN_ERROR8Interstitial cooldown active
AdError.INTERSTITIAL_ALREADY_SHOWN_ERROR9Interstitial already shown
AdError.TIME_OUT_ERROR10Ad request timed out
AdError.ADAPTER_NOT_FOUND_ERROR11Mediation adapter not found
AdError.BLOCKED_BY_GDPR12Request blocked by GDPR
AdError.AD_EXPIRED13Ad has expired

New Error in v6

Error ConstantError CodeDescription
AdError.NO_ADAPTER_FOUND_FOR_PLACEMENT_ID14No adapter configured for specific placement ID
No Migration Needed

Since error constants are unchanged, your existing error handling code will work without modifications in v6.

Native Ads

The native ad classes have been renamed to remove the MNG prefix. The ad loading, rendering, and interaction logic remains the same.

Class Renames

v5 (Old)v6 (New)
MNGAdsFactoryAdsFactory
MNGNativeObjectNativeObject
MNGPreferencePreference
MNGGenderGender

Factory Initialization

Before (v5)

MNGAdsFactory mngAdsNativeAdsFactory = new MNGAdsFactory(getActivity());
mngAdsNativeAdsFactory.setPlacementId("/YOUR_APP_ID/PLACEMENT_ID");

After (v6)

AdsFactory adsNativeAdsFactory = new AdsFactory(getActivity());
adsNativeAdsFactory.setPlacementId("/YOUR_APP_ID/PLACEMENT_ID");

Loading with Preferences

Before (v5)

MNGPreference mngPreference = new MNGPreference();
mngPreference.setAge(28);
mngPreference.setGender(MNGGender.MNGGenderFemale);
mngAdsNativeAdsFactory.loadNative(mngPreference);

After (v6)

Preference preference = new Preference();
preference.setAge(28);
preference.setGender(Gender.GenderFemale);
adsNativeAdsFactory.loadNative(preference);

Native Ad Callbacks

Before (v5)

mngAdsNativeAdsFactory.setNativeListener(new NativeListener() {
@Override
public void nativeObjectDidLoad(MNGNativeObject nativeObject) {
Log.d(TAG, "Native ad loaded");
// Use nativeObject to render your custom ad view
}

@Override
public void nativeObjectDidFail(Exception adsException) {
Log.e(TAG, "Native ad failed to load: " + adsException.toString());
}
});

After (v6)

adsNativeAdsFactory.setNativeListener(new NativeListener() {
@Override
public void nativeObjectDidLoad(NativeObject nativeObject) {
Log.d(TAG, "Native ad loaded");
// Use nativeObject to render your custom ad view
}

@Override
public void nativeObjectDidFail(Exception adsException) {
Log.e(TAG, "Native ad failed to load: " + adsException.toString());
}
});

AdChoice Position

Before (v5)

mngPreference.setAdChoicePosition(MNGPreference.TOP_LEFT);

After (v6)

preference.setAdChoicePosition(Preference.TOP_LEFT);

Other Ad Format Classes

The other ad format classes (InterstitialAd, RewardedAd, BannerView) and their listener interfaces remain unchanged in v6. No migration is needed for those formats.

Quick Find-and-Replace Summary

For most projects, the migration can be completed with a few find-and-replace operations:

FindReplace With
BlueStack.INSTANCE (Java)MobileAds.INSTANCE
BlueStack. (Kotlin)MobileAds.
BlueStackPrivacySettingsPrivacySettings
MNGAdsFactoryAdsFactory
MNGNativeObjectNativeObject
MNGPreferencePreference
MNGGenderGender
MNGGender.MNGGenderUnknownGender.GenderUnknown
MNGGender.MNGGenderMaleGender.GenderMale
MNGGender.MNGGenderFemaleGender.GenderFemale
AdSize (banner package)BannerAdSize
astuce

After running find-and-replace, build your project and fix any remaining compiler errors. The Android Studio compiler will flag any references to the old class names that were missed.

Need Help?

If you encounter issues during migration, please reach out to us. The v5 documentation is still available at Android v5 for reference.