adb react native code example

Example 1: run react native app on android device

#enable debug mode on yur device

$ adb devices
List of devices attached
emulator-5554 offline   # Google emulator
14ed2fcc device         # Physical device

$ npx react-native run-android
Try:
$ react-native run-android --deviceId=14ed2fcc

#use adb reverse
$ adb -s <device name> reverse tcp:8081 tcp:8081

NOTE:
You can also use the React Native CLI to generate and run a Release build
(e.g. npx react-native run-android --variant=release).

Example 2: admob react native

# Install & setup the app module
yarn add @react-native-firebase/app

# Install the admob module
yarn add @react-native-firebase/admob

#create admob project 
// <project-root>/firebase.json
{
  "react-native": {
    "admob_android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
    "admob_ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}

#create Ads @ admob and link it to firebase
//add the following code to your admob file
import admob, { MaxAdContentRating, InterstitialAd, RewardedAd, BannerAd, TestIds  } from '@react-native-firebase/admob';

admob()
  .setRequestConfiguration({
    // Update all future requests suitable for parental guidance
    maxAdContentRating: MaxAdContentRating.PG,

    // Indicates that you want your content treated as child-directed for purposes of COPPA.
    tagForChildDirectedTreatment: true,

    // Indicates that you want the ad request to be handled in a
    // manner suitable for users under the age of consent.
    tagForUnderAgeOfConsent: true,
  })
  .then(() => {
    // Request config successfully set!
  });


# Interstitial
InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL);

# Rewarded
RewardedAd.createForAdRequest(TestIds.REWARDED);

# Banners
<BannerAd
          unitId={TestIds.BANNER}
          size={BannerAdSize.FULL_BANNER}
          requestOptions={{
            requestNonPersonalizedAdsOnly: true,
          }}
        />