Skip to content

C++

Adkit for AD(X): C++

Creating Development Environment

Android

Build the Prebuilt-Firebase-Library and embedded AdKit SourceCode to use the AdKit. Android Studio 3.0 and later version are recommended.

  1. ExternalNativeBuild

    • [Case 1] Using #ndk-build
    // ‘Android.mk’
    $(call import-add-path,$(LOCAL_PATH)/../../..) #Path setup to install HIVEAdKit module
    $(call import-module, HIVEAdKit) #Load the configuration of HIVEAdKit module
    $(call import-module, HIVEAdKit/firebase_cpp_sdk) #Load the prebuilt version of firebase_cpp_sdk module to use HIVEAdKit
    
    • [Case 2] Using #cmake
    // 'CMakeList.txt'
    
    set(HIVEADKIT_DIR_PATH ....../HIVEAdKit) #Path setup to install HIVEAdKit module
    #Import HIVEAdKit library after add_library (MyGame ...)
    add_subdirectory(${HIVEADKIT_DIR_PATH}) #HIVEAdKit library & macro load
    use_hiveadkit_prebuilt(${HIVEADKIT_DIR_PATH} MyGame) #Import the library import automatic macro to build target
    
  2. Add the followings to the build.gradle file.

    android {
    ...
    sourceSets.main {
            java.srcDirs "src" , "../../HIVEAdKit/Android/java" // HIVEAdKit JavaPlugin Source Path
    }
    ...
    }
    
    
    gradle.ext.firebase_cpp_sdk_dir = "../HIVEAdKit/firebase_cpp_sdk" // setup HIVEAdKit/firebase_cpp_sdk Path
    apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"
    firebaseCpp.dependencies {
    admob
    }
    
  3. In case of using AD(X) or ADOP with AdMob-AdManager Service, add the followings to the AndroidManifest.xml file.

    <application>
    <meta-data android:name="com.google.android.gms.ads.AD_MANAGER_APP" android:value="true" />
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-3940256099942544~3347511713"/> <!-- Sample value -->
    </application>
    
  4. In case of using AD(X), add the followings to the build.gradle file.

    android {
    ...
    dependencies {
        ...
        implementation "com.github.adxcorp.ADXLibrary_Android:adx-library-rewarded-video:1.16.2"
    }
    }
    

iOS

Build the Firebase-Framework and the included AdKit source code to use this feature.

  1. Drag and drop the HIVEAdKit/src and HIVEAdKit/include folders to XCode project.

    • Include all files with .cpp, .hpp and .mm extensions.
    • AdKit provides bridge-pattern code for the actual use.
  2. Add HIVEAdKit/firebase_cpp_sdk/frameworks/ios/universal to Project > Build Settings > Search Paths > Framework Search Path.

  3. Add HIVEAdKit/firebase_cpp_sdk/include to Project > Build Settings > Search Paths > Header Search Path.

  4. Add -framework "firebase" and -framework "firebase_admob" to Project > Build Settings > Other Flags.

  5. Add the following to CocoaPods settings.

    $pod ‘Firebase/AdMob’
    
  6. In case of using AD(X), add the followings to CocoaPods settings.

    $source 'https://github.com/adxcorp/AdxLibrary_iOS_Release.git'
    $pod 'ADXLibrary'
    
  7. In order to download the latest SDK of iOS from Xcode, you need to execute the following command.

    pod install --repo-update
    

The key for a test ad in AdMob is set in the following example.

```
#if defined(ANDROID)
const char* appId =                  "ca-app-pub-3940256099942544~3347511713";
const char* rewardVideoUnitId =      "ca-app-pub-3940256099942544/5224354917";
const char* InterstitialAdUnitId =   "ca-app-pub-3940256099942544/1033173712";
const char* AdaptiveBannerAdUnitId = "ca-app-pub-3940256099942544/6300978111";
#else // iOS
const char* appId =                  "ca-app-pub-3940256099942544~1458002511";
const char* rewardVideoUnitId =      "ca-app-pub-3940256099942544/1712485313";
const char* InterstitialAdUnitId =   "ca-app-pub-3940256099942544/4411468910";
const char* AdaptiveBannerAdUnitId = "ca-app-pub-3940256099942544/2934735716";
#endif
```

Features

If you use Reward Video API from AdKit C++ with Hive SDK, sending log data depends on the implemented RewardVideo API. Log data is sent to Analytics server, and this feature is available with the following version and later of Hive SDK. It doesn't work if Hive SDK is not initialized or existed.

  • Hive SDK v4.11.0

How to use AdKit is as follows.

Initializing AdMob

Required step before initializing, loading and showing all types of advertisement (AD)

    //App ID, API key, and Project ID must be specified in App options.
    firebase::AppOptions appOptions = firebase::AppOptions();
    #ifdef __ANDROID__
        // Android Only
        appOptions.set_app_id("331526026701");
        appOptions.set_api_key("AIzaSyAxOUz9NQtpZZD_XvfD5L7V1dZZ96tYwZ8");//
        appOptions.set_project_id("core-cocos-test");
    #endif
    firebase::InitResult result = HIVEAdKit::AdMobInitialize(appOptions);
    if(result == firebase::kInitResultSuccess) {
        // AdMob initialization successful
    }

Rewarded type

    // Initialize
    auto rewardVideo = HIVEAdKit::RewardVideo::Initialize(rewardVideoUnitId, this, getAdMobViewParent(),
                                                                                                [=](const firebase::Future< void >& completed_future) {
        if (completed_future.error() == 0) {
                // Initiallized successfully
        }
    });
    // Load
    // Send AD loading information to Analytics
    std::string adPlacement = "CocosCPP-RewardVideo-Load-AdditionalInfo";
    firebase::admob::AdRequest my_ad_request = {};
    HIVEAdKit::RewardVideo::Load(*rewardVideo,  my_ad_request, adPlacement,
                                                                                            [=](const firebase::Future< void >& completed_future) {
        if (completed_future.error() == 0) {
                // Loaded successfully
        }
    });
    // Show
    // Send AD loading information to Analytics
    std::string adPlacement = "CocosCPP-RewardVideo-Show-AdditionalInfo";
    HIVEAdKit::RewardVideo::Show(*rewardVideo, adPlacement,
                                                                                            [=](const firebase::Future< void >& completed_future) {
        if (completed_future.error() == 0) {
                // Shown successfully
        }
    });

Interstitial type

// Initialize
auto interstitial = HIVEAdKit::Interstitial::Initialize(InterstitialAdUnitId, this, getAdMobViewParent(),
                                               [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Initiallized successfully
   }
});
// Load
// Send AD loading information to Analytics
std::string adPlacement = "CocosCPP-Interstitial-Load-AdditionalInfo";
firebase::admob::AdRequest my_ad_request = {};
HIVEAdKit::Interstitial::Load(*interstitial, my_ad_request, adPlacement,
                                             [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Loaded successfully
   }
});
// Show
// Send AD loading information to Analytics
std::string adPlacement = "CocosCPP-Interstitial-Show-AdditionalInfo";
HIVEAdKit::Interstitial::Show(*interstitial, adPlacement,
                                             [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Shown successfully
   }
});

Adaptive Banner type

// Initialize
auto adaptiveBanner = HIVEAdKit::AdaptiveBanner::Initialize(AdaptiveBannerAdUnitId,
                                                                   this,
                                                                   getAdMobViewParent(),
                                                                   banner_ad_size,
                                                                   bannerPosition,
                                               [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Initialized successfully
   }
});
// Set banner position
HIVEAdKit::AdaptiveBanner::SetPosition(*adaptiveBanner, bannerPosition, [=](const firebase::Future< void >& completed_future) {
});
// Load
// Send AD loading information to Analytics
std::string adPlacement = "CocosCPP-AdaptiveBanner-Load-AdditionalInfo";
firebase::admob::AdRequest my_ad_request = {};
HIVEAdKit::AdaptiveBanner::Load(*adaptiveBanner, my_ad_request, adPlacement,
                                             [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Loaded successfully
   }
});
// Show
// Send AD loading information to Analytics
std::string adPlacement = "CocosCPP-AdaptiveBanner-Show-AdditionalInfo";
HIVEAdKit::AdaptiveBanner::Show(*adaptiveBanner, adPlacement,
                                             [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Shown successfully
   }
});
// Hide
HIVEAdKit::AdaptiveBanner::Hide(*adaptiveBanner,
                                             [=](const firebase::Future< void >& completed_future) {
if (completed_future.error() == 0) {
       // Hidden successfully
   }
});

Supporting iOS 14

Following is SKAdNetwork list of AD(X) for supporting iOS 14 and later version. AdKitPostprocess is based on the update on January 29, 2021. Don't forget to check the latest update.

Unity integrate notice

  1. Follow the procedures below to sync the ADXUnityPackage 1.10.0 or higher under the Unity Engine 2019.4 or higher envorinment.

    • In the Unity editor, check Assets > External Dependency Manager > iOS Resolver > Settings > Add use_frameworks! to Podfile and Link frameworks statically, then save it.

    • Add OMSDK_Mopub.xcframework (Pods/mopub-ios-sdk/Frameworks/OMSDK_Mopub.xcframework) on iOS PROJECT > Targets > Build Phases > Embed Frameworks.

    • Add FBSDKCoreKit_Basics.xcframework (Pods/FBSDKCoreKit_Basics/XCFrameworks/FBSDKCoreKit_Basics.xcframework) on Targets > Build Phases > Embed Frameworks to sync the ADXUnityPackage 1.10.3 or higher under the Unity Engine 2019.4 or higher envorinment.

  2. If the App ID on GoogleMobileAdsSettings is removed, go to Unity > Assets > Google Mobile Ads > Settings and select the Delay app measurement checkbox, then clear it again.

Issue Check

If you develop your game with Cocos2D-X, some of FlatBuffers libraries in Cocos2D-X engine and Firebase-embedded libraries are duplicated. To prevent the duplication, try not to include the FlatBuffers libraries or directly build the open-source libraries provided by Firebase. Firebase includes the below libraries. If the libraries crash due to duplication, use Firebase open-source libraries for building your project manually.

  • Curl
  • FlatBuffers
  • libuv
  • Nanopb
  • uWebSockets
  • Zlib