npm.io
0.4.0 • Published 4 months ago

@empower-nokta/react-native-empower-mobile-ads

Licence
MIT
Version
0.4.0
Deps
0
Size
65 kB
Vulns
0
Weekly
0
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

@empower-nokta/react-native-mobile-ads

React Native bridge for the Empower Mobile Ads SDK (Android & iOS).

Supports banner, interstitial, rewarded, app open, and preroll ad formats.

Requirements

  • React Native 0.71+
  • Android minSdkVersion 21 (Android 5.0)
  • iOS Deployment Target 13.0+
  • New Architecture: supported via React Native interop layer (0.74+)

Installation

npm install @empower-nokta/react-native-mobile-ads

The package supports auto-linking — no manual linking required for React Native 0.60+.

Android Setup

After installing, you need to configure 3 things in your Android project:

Step 1: Add Maven Repository

The Empower native SDK is hosted on a private Maven repository. Add it to your project.

If your project uses settings.gradle (React Native 0.73+):

// android/settings.gradle
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url "https://maven.empower.net/release" }  // Add this
    }
}

If your project uses allprojects in build.gradle (older RN):

// android/build.gradle
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://maven.empower.net/release" }  // Add this
    }
}
Step 2: Add Kotlin Compatibility Property

The Empower native SDK uses Kotlin 2.3.0. Add this line to android/gradle.properties:

kotlin.suppressKotlinVersionCompatibilityCheck=2.3.0

Note: The SDK automatically handles the Kotlin compiler metadata compatibility. You only need this one property — no resolutionStrategy or compiler flags required.

Step 3: New Architecture — SoLoader Fix (RN 0.76+ with newArchEnabled=true only)

If your app uses New Architecture (newArchEnabled=true in gradle.properties), you must update MainApplication.kt to use OpenSourceMergedSoMapping. This is required because React Native 0.76+ merges native libraries into a single .so file:

// android/app/src/main/java/com/yourapp/MainApplication.kt

// Add this import:
import com.facebook.react.soloader.OpenSourceMergedSoMapping

// Change SoLoader.init in onCreate:
override fun onCreate() {
    super.onCreate()
    SoLoader.init(this, OpenSourceMergedSoMapping)  // was: SoLoader.init(this, false)
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
        load()
    }
}

Old Architecture apps (newArchEnabled=false) do not need this change.

Step 4: Build and Run
cd android && ./gradlew clean && cd ..
npx react-native run-android

iOS Setup

Step 1: Add CocoaPods Source

Add the Empower specs source to the top of your ios/Podfile:

source 'https://github.com/empowernet/specs.git'
source 'https://cdn.cocoapods.org/'

Ensure use_frameworks! is present in your target block:

target 'YourApp' do
  use_frameworks!
  # ...existing pods...
end
Step 2: Update Info.plist

Add your Google Ads Application ID to ios/YourApp/Info.plist:

<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>
Step 3: Install Pods and Run
cd ios && pod install --repo-update && cd ..
npx react-native run-ios

Usage

Initialize the SDK
import { init, setDebugMode, setLogLevel } from '@empower-nokta/react-native-mobile-ads';

// Call early in your app (e.g., App.tsx useEffect)
async function initAds() {
  setDebugMode(__DEV__);
  setLogLevel(__DEV__ ? 'all' : 'none');

  await init({
    appAdIdentifier: 'YOUR_APP_IDENTIFIER',
  });
}
Banner Ads
import { EmpowerBannerAd } from '@empower-nokta/react-native-mobile-ads';

function MyScreen() {
  return (
    <EmpowerBannerAd
      zoneId="YOUR_BANNER_ZONE_ID"
      onAdStatusChanged={(e) => console.log('Banner:', e.nativeEvent)}
      style={{ width: '100%', minHeight: 50 }}
    />
  );
}
Interstitial Ads
import {
  loadInterstitialAd,
  showInterstitial,
  addEventListener,
  EmpowerAdsEvents,
} from '@empower-nokta/react-native-mobile-ads';

// Listen for status changes
const unsubscribe = addEventListener(EmpowerAdsEvents.INTERSTITIAL_STATUS, (event) => {
  console.log('Interstitial status:', event.status, event.zoneId);
});

// Preload
await loadInterstitialAd('YOUR_INTERSTITIAL_ZONE_ID');

// Show when ready
await showInterstitial('YOUR_INTERSTITIAL_ZONE_ID');

// Cleanup
unsubscribe();
Rewarded Ads
import {
  loadRewardedAd,
  showRewarded,
  addEventListener,
  EmpowerAdsEvents,
} from '@empower-nokta/react-native-mobile-ads';

const unsubscribe = addEventListener(EmpowerAdsEvents.REWARDED_STATUS, (event) => {
  if (event.status === 'REWARDED') {
    // Grant reward to user
  }
});

await loadRewardedAd('YOUR_REWARDED_ZONE_ID');
await showRewarded('YOUR_REWARDED_ZONE_ID');

unsubscribe();
App Open Ads
import { loadAppOpenAd, showAppOpen } from '@empower-nokta/react-native-mobile-ads';

await loadAppOpenAd('YOUR_APP_OPEN_ZONE_ID');
await showAppOpen('YOUR_APP_OPEN_ZONE_ID');
Settings
import {
  setAdsDisabled,
  setNonPersonalizedAds,
  setDebugMode,
  setLogLevel,
} from '@empower-nokta/react-native-mobile-ads';

setAdsDisabled(false);
setNonPersonalizedAds(true); // GDPR compliance
setDebugMode(true);
setLogLevel('all'); // 'all' | 'default' | 'error' | 'warning' | 'none'
Shutdown
import { shutdown } from '@empower-nokta/react-native-mobile-ads';

shutdown();

API Reference

Function Returns Description
init(config) Promise<boolean> Initialize the SDK
isSdkInitialized() Promise<boolean> Check if SDK is ready
setAdsDisabled(bool) void Disable/enable all ads
setNonPersonalizedAds(bool) void GDPR non-personalized mode
setDebugMode(bool) void Toggle debug logging
setLogLevel(level) void Set log verbosity
loadInterstitialAd(zoneId) Promise<boolean> Preload interstitial
showInterstitial(zoneId) Promise<boolean> Show interstitial
loadRewardedAd(zoneId) Promise<boolean> Preload rewarded ad
showRewarded(zoneId) Promise<boolean> Show rewarded ad
loadAppOpenAd(zoneId) Promise<boolean> Preload app open ad
showAppOpen(zoneId) Promise<boolean> Show app open ad
loadPrerollAd(zoneId) Promise<boolean> Load preroll ad (use <EmpowerPrerollView> instead)
pausePreroll(zoneId) void Pause preroll playback
resumePreroll(zoneId) void Resume preroll playback
destroyPreroll(zoneId) void Destroy preroll ad
shutdown() void Shutdown SDK
addEventListener(event, cb) () => void Subscribe to events

Events

Event Payload
EmpowerAds_onSdkReady {}
EmpowerAds_onSdkFailed { error: string }
EmpowerAds_onBannerStatusChanged { status, zoneId, adUnitId }
EmpowerAds_onInterstitialStatusChanged { status, zoneId }
EmpowerAds_onRewardedStatusChanged { status, zoneId }
EmpowerAds_onAppOpenStatusChanged { status, zoneId }
EmpowerAds_onPrerollStatusChanged { status, zoneId }
EmpowerAds_onPrerollAdEvent { type, zoneId }

Troubleshooting

"Could not resolve net.empower.mobile.ads:empower-mobile-ads"

You need to add the Empower Maven repository. See Step 1.

"Module compiled with an incompatible version of Kotlin"

Add kotlin.suppressKotlinVersionCompatibilityCheck=2.3.0 to android/gradle.properties. See Step 2. The compiler flag (-Xskip-metadata-version-check) is injected automatically by the SDK.

Important: Do NOT use resolutionStrategy.force to downgrade kotlin-stdlib to 1.9.x — this will cause a runtime crash (NoClassDefFoundError: SpillingKt) because the Empower native SDK requires Kotlin 2.3.0 stdlib classes at runtime.

"dlopen failed: library libreact_featureflagsjni.so not found" (New Architecture only)

Your MainApplication.kt needs OpenSourceMergedSoMapping. See Step 3.

"NoClassDefFoundError: kotlin/coroutines/jvm/internal/SpillingKt"

You have a resolutionStrategy.force that downgrades kotlin-stdlib to 1.9.x. Remove it — the Empower SDK needs kotlin-stdlib 2.3.0 at runtime.

iOS: "No such module 'EmpowerMobileAds'"

Run pod install --repo-update in your ios/ directory. Ensure the Empower specs source is in your Podfile and use_frameworks! is enabled.

TurboModuleRegistry.getEnforcing crash

This usually means Metro is serving a JS bundle from a different project. Make sure Metro is running from your project root:

npx react-native start --reset-cache

The module is compatible with New Architecture via React Native's interop layer (RN 0.74+).

Banner ad loads but is not visible

Ensure the EmpowerBannerAd component has explicit dimensions:

<EmpowerBannerAd
  zoneId="YOUR_ZONE_ID"
  style={{ width: '100%', minHeight: 50 }}
/>
"No fill" from Google Ad Manager

This means no ad is available for your ad unit. Check that your applicationId in build.gradle matches the package name configured in your Google Ad Manager account.

SDK initializes but init() Promise never resolves

The init() Promise resolves when the SDK is fully ready (including Google Mobile Ads initialization). This can take a few seconds. If it never resolves, check logcat for errors:

adb logcat | grep EmpowerAds

Compatibility Matrix

React Native Kotlin Compiler Architecture Extra Setup
0.71 – 0.75 1.9.x Old Arch only Step 1 + Step 2
0.76 – 0.77 1.9.x Old Arch Step 1 + Step 2
0.76 – 0.77 1.9.x New Arch Step 1 + Step 2 + Step 3
0.78+ 2.0+ Old or New Arch Step 1 only

Notes

  • Cross-platform: Both Android and iOS are fully supported.
  • Preroll Ads: Use the <EmpowerPrerollView> component for inline preroll video ads. Use pausePreroll/resumePreroll/destroyPreroll for lifecycle management.
  • Min SDK: Android API 21+ (Android 5.0), iOS 13.0+

License

MIT

Keywords