React-native-firebase: Not receive phone auth sms

Created on 17 Dec 2019  路  22Comments  路  Source: invertase/react-native-firebase

Issue

Even if auth().signInWithPhoneNumber is executed successfully, no SMS message is received.

import auth from '@react-native-firebase/auth';

const signginPhoneNumber = () => {
  setIsFetching(true);

  auth().signInWithPhoneNumber(phoneInputRef.current.getValue(), true)
    .then((confirmResult) => {
       // Todo
    })
    .catch(console.error);
};

Project Files






Javascript

Click To Expand

#### `package.json`:

{
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android --appIdSuffix debug --variant=devDebug",
    "ios": "react-native run-ios --simulator='iPhone 11 Pro Max'",
    "web": "expo start --web",
    "pod": "cd ios && pod install",
    "clean:ios": "rm -rf ios/build && rm -rf ios/index && rm -rf ios/Pods",
    "clean:android": "cd android && ./gradlew clean",
    "dev:bundle:android": "cd android && ./gradlew assembleDevDebug",
    "bundle:ios": "react-native bundle --platform='ios' --dev false --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --assets-dest='ios'",
    "build:android:staging": "cd android && ENVFILE=.env ./gradlew assembleStStaging",
    "build:android:production": "cd android && ENVFILE=.env.production ./gradlew assembleProductionRelease",
    "upload:ios": "xcrun altool --verbose --upload-app",
    "postinstall": "jetify"
  },
  "dependencies": {
    "@expo/vector-icons": "^10.0.0",
    "@react-native-community/push-notification-ios": "^1.0.3",
    "@react-native-firebase/app": "^6.2.0",
    "@react-native-firebase/auth": "^6.2.0",
    "@react-native-firebase/dynamic-links": "^6.2.0",
    "@react-native-firebase/firestore": "^6.2.0",
    "@react-native-firebase/functions": "^6.2.0",
    "@react-native-firebase/messaging": "^6.2.0",
    "@react-native-firebase/storage": "^6.2.0",
    "@sentry/react-native": "^1.0.9",
    "base-64": "^0.1.0",
    "expo": "^35.0.0",
    "expo-analytics-amplitude": "~7.0.0",
    "expo-constants": "~7.0.0",
    "expo-contacts": "~7.0.0",
    "expo-facebook": "~7.0.0",
    "expo-image-picker": "~7.0.0",
    "expo-permissions": "~7.0.0",
    "expo-store-review": "~1.0.0",
    "expo-web-browser": "~7.0.0",
    "firebase": "^7.2.2",
    "libphonenumber-js": "^1.7.22",
    "lottie-react-native": "~2.6.1",
    "moment": "^2.24.0",
    "prop-types": "^15.7.2",
    "react": "16.8.3",
    "react-dom": "16.8.3",
    "react-native": "0.59.10",
    "react-native-audio": "^4.3.0",
    "react-native-config": "^0.11.7",
    "react-native-country-picker-modal": "^1.9.8",
    "react-native-device-info": "^5.3.1",
    "react-native-fbsdk": "0.10.3",
    "react-native-gesture-handler": "~1.3.0",
    "react-native-gifted-chat": "^0.9.11",
    "react-native-keyboard-aware-scroll-view": "^0.9.1",
    "react-native-localize": "^1.3.1",
    "react-native-masked-text": "^1.13.0",
    "react-native-paper": "^3.0.0",
    "react-native-phone-input": "^0.2.4",
    "react-native-reanimated": "~1.3.0",
    "react-native-screens": "1.0.0-alpha.23",
    "react-native-share": "1.1.3",
    "react-native-slider": "^0.11.0",
    "react-native-snap-carousel": "^3.8.0",
    "react-native-sound": "^0.11.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-status-bar-height": "^2.3.1",
    "react-native-swiper": "^1.6.0-nightly.5",
    "react-native-unimodules": "0.6.0",
    "react-native-web": "^0.11.7",
    "react-navigation": "^3.11.0",
    "react-navigation-material-bottom-tabs": "^1.0.0",
    "rn-fetch-blob": "0.10.15"
  },
  "devDependencies": {
    "@babel/core": "^7.6.0",
    "babel-jest": "24.9.0",
    "babel-preset-expo": "^7.0.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.17.3",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "^7.13.0",
    "jest": "24.9.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "private": true
}

#### `firebase.json` for react-native-firebase v6:
# N/A
### iOS
Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like:

platform :ios, '10.0'

require_relative '../node_modules/react-native-unimodules/cocoapods'

target 'leavoice' do
  # Pods for leavoice
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTBlob',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
  ]

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
  pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec'
  pod 'RNScreens', :path => '../node_modules/react-native-screens'

  use_unimodules!

  pod 'react-native-config', :path => '../node_modules/react-native-config'


  pod 'lottie-react-native', :path => '../node_modules/lottie-react-native'

  pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app'

  pod 'RNFBAuth', :path => '../node_modules/@react-native-firebase/auth'

  pod 'RNFBFirestore', :path => '../node_modules/@react-native-firebase/firestore'

  pod 'RNFBFunctions', :path => '../node_modules/@react-native-firebase/functions'

  pod 'RNFBStorage', :path => '../node_modules/@react-native-firebase/storage'

  pod 'RNSentry', :path => '../node_modules/@sentry/react-native'

  pod 'RNFBMessaging', :path => '../node_modules/@react-native-firebase/messaging'

  pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios'

  pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'

  pod 'RNAudio', :path => '../node_modules/react-native-audio'

  pod 'RNSound', :path => '../node_modules/react-native-sound'

  pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk'

  pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

  pod 'RNFBDynamicLinks', :path => '../node_modules/@react-native-firebase/dynamic-links'

  pod 'RNShare', :path => '../node_modules/react-native-share'

  pod 'rn-fetch-blob', :path => '../node_modules/rn-fetch-blob'

  pod 'RNLocalize', :path => '../node_modules/react-native-localize'

end

#### `AppDelegate.m`:
/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#import "RNSplashScreen.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@import Firebase;

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }

  // https://firebase.google.com/docs/cloud-messaging/ios/client?hl=ja
  if ([UNUserNotificationCenter class] != nil) {
    // iOS 10 or later
    // For iOS 10 display notification (sent via APNS)
    [UNUserNotificationCenter currentNotificationCenter].delegate = self;
    UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
        UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
    [[UNUserNotificationCenter currentNotificationCenter]
        requestAuthorizationWithOptions:authOptions
        completionHandler:^(BOOL granted, NSError * _Nullable error) {
          // ...
        }];
  } else {
    // iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
    UIUserNotificationType allNotificationTypes =
    (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
    UIUserNotificationSettings *settings =
    [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
    [application registerUserNotificationSettings:settings];
  }

  [application registerForRemoteNotifications];

  self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"leavoice" initialProperties:nil];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  [super application:application didFinishLaunchingWithOptions:launchOptions];

  [[FBSDKApplicationDelegate sharedInstance] application:application
    didFinishLaunchingWithOptions:launchOptions];

  [RNSplashScreen show];

  return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

  BOOL handledFb = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options];
  BOOL handledDynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];

  // Add any custom logic here.
  return handledFb || handledDynamicLink;
}

- (BOOL)application:(UIApplication *)application
continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:
#if defined(__IPHONE_12_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_0)
(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> *_Nullable))restorationHandler {
#else
    (nonnull void (^)(NSArray *_Nullable))restorationHandler {
#endif  // __IPHONE_12_0
  BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL
                                                          completion:^(FIRDynamicLink * _Nullable dynamicLink,
                                                                       NSError * _Nullable error) {
                                                            // ...
                                                          }];
  return handled;
}

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
  NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
  // You can inject any extra modules that you would like here, more information at:
  // https://facebook.github.io/react-native/docs/native-modules-ios.html#dependency-injection
  return extraModules;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#ifdef DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end


Android

Click To Expand

#### Have you converted to AndroidX? - [x] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 21
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


wrapper {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

#### `android/app/build.gradle`:
apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    bundleInDevDebug: true,
    bundleInStStaging: true,
    devDisabledInStStaging: true,
]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/@sentry/react-native/sentry.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.holoash.leavoice"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 78
        versionName "3.1.1"
        resValue "string", "build_config_package", "com.holoash.leavoice"
    }
    signingConfigs {
        staging {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
        staging {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            applicationIdSuffix ""
            signingConfig signingConfigs.staging
            matchingFallbacks = ['debug']
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    flavorDimensions "default"
    productFlavors {
        dev {

        }
        st {
            applicationId "com.holoash.voicechat.staging"
            versionCode 19
            versionName "1.0.0"
        }
        production {

        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation project(':react-native-localize')
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-share')
    implementation project(':@react-native-firebase_dynamic-links')
    implementation project(':react-native-device-info')
    implementation project(':react-native-fbsdk')
    implementation project(':react-native-sound')
    implementation project(':react-native-audio')
    implementation project(':react-native-splash-screen')
    implementation project(':@react-native-firebase_messaging')
    implementation project(':@sentry_react-native')
    implementation project(':@react-native-firebase_storage')
    implementation project(':@react-native-firebase_functions')
    implementation project(':@react-native-firebase_firestore')
    implementation project(':@react-native-firebase_auth')
    implementation project(':@react-native-firebase_app')
    implementation project(':lottie-react-native')
    implementation project(':react-native-config')
    implementation project(':react-native-screens')
    implementation project(':react-native-reanimated')
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    addUnimodulesDependencies()
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'

#### `android/settings.gradle`:
apply from: '../node_modules/react-native-unimodules/gradle.groovy'
include ':react-native-localize'
project(':react-native-localize').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-localize/android')
include ':rn-fetch-blob'
project(':rn-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/rn-fetch-blob/android')
include ':react-native-share'
project(':react-native-share').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-share/android')
include ':@react-native-firebase_dynamic-links'
project(':@react-native-firebase_dynamic-links').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/dynamic-links/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')
include ':react-native-sound'
project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
include ':react-native-audio'
project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android')
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':@react-native-firebase_messaging'
project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/messaging/android')
include ':@sentry_react-native'
project(':@sentry_react-native').projectDir = new File(rootProject.projectDir, '../node_modules/@sentry/react-native/android')
include ':@react-native-firebase_storage'
project(':@react-native-firebase_storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/storage/android')
include ':@react-native-firebase_functions'
project(':@react-native-firebase_functions').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/functions/android')
include ':@react-native-firebase_firestore'
project(':@react-native-firebase_firestore').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/firestore/android')
include ':@react-native-firebase_auth'
project(':@react-native-firebase_auth').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/auth/android')
include ':@react-native-firebase_app'
project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-firebase/app/android')
include ':lottie-react-native'
project(':lottie-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/lottie-react-native/src/android')
include ':react-native-config'
project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')
include ':react-native-screens'
project(':react-native-screens').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screens/android')
include ':react-native-reanimated'
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
includeUnimodulesProjects()

rootProject.name = 'leavoice'

include ':app'

#### `MainApplication.java`:
package com.holoash.leavoice;

import android.app.Application;


import android.os.Build;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;


import com.facebook.react.ReactApplication;
import com.reactcommunity.rnlocalize.RNLocalizePackage;
import com.RNFetchBlob.RNFetchBlobPackage;
import cl.json.RNSharePackage;
import io.invertase.firebase.dynamiclinks.ReactNativeFirebaseDynamicLinksPackage;
import com.learnium.RNDeviceInfo.RNDeviceInfo;
import com.facebook.CallbackManager;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.zmxv.RNSound.RNSoundPackage;
import com.rnim.rn.audio.ReactNativeAudioPackage;
import org.devio.rn.splashscreen.SplashScreenReactPackage;
import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage;
import io.sentry.RNSentryPackage;
import io.invertase.firebase.storage.ReactNativeFirebaseStoragePackage;
import io.invertase.firebase.functions.ReactNativeFirebaseFunctionsPackage;
import io.invertase.firebase.firestore.ReactNativeFirebaseFirestorePackage;
import io.invertase.firebase.auth.ReactNativeFirebaseAuthPackage;
// import io.invertase.firebase.ReactNativeFirebaseAppPackage;
import io.invertase.firebase.app.ReactNativeFirebaseAppPackage;
import com.airbnb.android.react.lottie.LottiePackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.holoash.leavoice.generated.BasePackageList;
import com.swmansion.reanimated.ReanimatedPackage;
import com.swmansion.rnscreens.RNScreensPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import cl.json.ShareApplication;

import org.unimodules.adapters.react.ReactAdapterPackage;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.Package;
import org.unimodules.core.interfaces.SingletonModule;
import expo.modules.constants.ConstantsPackage;
import expo.modules.permissions.PermissionsPackage;
import expo.modules.filesystem.FileSystemPackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ShareApplication, ReactApplication {
  private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
  protected static CallbackManager getCallbackManager() {
    return mCallbackManager;
  }

  private void createNotificationChannel() {
      // Create the NotificationChannel, but only on API 26+ because
      // the NotificationChannel class is new and not in the support library
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
          CharSequence name = "New messages";
          String description = "";
          int importance = NotificationManager.IMPORTANCE_HIGH;
          NotificationChannel channel = new NotificationChannel("new-messages", name, importance);
          channel.setDescription(description);
          // Register the channel with the system; you can't change the importance
          // or other notification behaviors after this
          NotificationManager notificationManager = getSystemService(NotificationManager.class);
          notificationManager.createNotificationChannel(channel);
      }
  }

  private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(
    new BasePackageList().getPackageList(),
    Arrays.<SingletonModule>asList()
  );

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNLocalizePackage(),
            new RNFetchBlobPackage(),
            new RNSharePackage(),
            new ReactNativeFirebaseDynamicLinksPackage(),
            new RNDeviceInfo(),
            new FBSDKPackage(mCallbackManager),
            new RNSoundPackage(),
            new ReactNativeAudioPackage(),
            new SplashScreenReactPackage(),
            new ReactNativeFirebaseMessagingPackage(),
            new RNSentryPackage(),
            new ReactNativeFirebaseStoragePackage(),
            new ReactNativeFirebaseFunctionsPackage(),
            new ReactNativeFirebaseFirestorePackage(),
            new ReactNativeFirebaseAuthPackage(),
            new ReactNativeFirebaseAppPackage(),
            new LottiePackage(),
            new ReactNativeConfigPackage(),
          new ReanimatedPackage(),
          new RNGestureHandlerPackage(),
          new RNScreensPackage(),
          new ModuleRegistryAdapter(mModuleRegistryProvider)
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);

    createNotificationChannel();
  }

  // https://github.com/react-native-community/react-native-share
  @Override
  public String getFileProviderAuthority() {
    return BuildConfig.APPLICATION_ID + ".provider";
  }
}

#### `AndroidManifest.xml`:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.holoash.leavoice">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <!-- OPTIONAL PERMISSIONS, REMOVE WHATEVER YOU DO NOT NEED -->
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

    <!-- These require runtime permissions on M -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <!-- END OPTIONAL PERMISSIONS -->

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:usesCleartextTraffic="true"
      android:authorities="${applicationId}.provider">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data
            android:host="leavoice.com"
            android:scheme="https" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <!-- fbsdk -->
      <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
      <activity android:name="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" />
      <activity android:name="com.facebook.CustomTabActivity" android:exported="true">
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
      </activity>

      <service
        android:name="com.google.firebase.messaging.FirebaseMessagingService"
        android:exported="false"
      >
        <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
      </service>
      <service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />

      <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@mipmap/notification"
      />

      <!-- https://github.com/expo/expo/tree/master/packages/expo-image-picker -->
      <activity
        android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
        android:theme="@style/Base.Theme.AppCompat">
      </activity>
    </application>

</manifest>


Environment

Click To Expand

**`react-native info` output:**

  React Native Environment Info:
    System:
      OS: macOS 10.14.5
      CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
      Memory: 325.01 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.16.0 - ~/.nodebrew/current/bin/node
      Yarn: 1.16.0 - ~/.nodebrew/current/bin/yarn
      npm: 6.4.1 - ~/.nodebrew/current/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 23.0.2, 25.0.0, 26.0.1, 26.0.3, 27.0.3, 28.0.2, 28.0.3
        System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-Q | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.4 AI-183.6156.11.34.5522156
      Xcode: 11.0/11A420a - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.10 => 0.59.10 
    npmGlobalPackages:
      react-native-git-upgrade: 0.2.7
      react-native: 0.61.5
- **Platform that you're experiencing the issue on**: - [x] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `6.2.0` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `No`

Most helpful comment

This is probably a carrier issue. I have mixed success with the SMS authentication.
If you use a test phone number (configured in phone authentication dashboard) and it works in testing, then I bet it is a mobile carrier not letting it through in your area.

Try with friend's number on different mobile carriers, and be patient, I bet at least some get through.

Makes it so that as a primary authentication or verification mechanism it is not very useful though. We settled on a local SMS sender for our initial country (Ecuador) because of this.

All 22 comments

This is probably a carrier issue. I have mixed success with the SMS authentication.
If you use a test phone number (configured in phone authentication dashboard) and it works in testing, then I bet it is a mobile carrier not letting it through in your area.

Try with friend's number on different mobile carriers, and be patient, I bet at least some get through.

Makes it so that as a primary authentication or verification mechanism it is not very useful though. We settled on a local SMS sender for our initial country (Ecuador) because of this.

@345ml
And should check to remove number from test number in Firebase.

@Vietvantue
Thank you.
I tried it, but it didn't work...

@mikehardy
I suspected a carrier problem, but the SMS message itself was working fine.
I will try other people's phone numbers.

I tried it with my colleague's number and received the code.

By the way, SMS messages are functioning normally on my Android device, and only the authentication code from Firebase cannot be received.

Does anyone have any idea about this matter?

(Sorry for unrelated questions about the library.)

Yes, these are "shortcodes", not regular SMS. And the carriers are really touch-y about them because they don't pay very well, so comparing receipt of google authentication codes with regular SMS is unfortunately not valid, and it is hard to know which carriers will work with SMS and which won't. I've seen reports online that phone numbers recently ported don't work also. So it's difficult to rely on unfortunately

The problem seems to be in deep darkness ...

Are there any permissions that need to be added to AndroidManifest.xml?

https://fir-ui-demo-84a6c.firebaseapp.com/

Even if it tried this, it was useless.
It will be a complete device problem.

Confirmed that Google 2-step verification SMS cannot be received.

It is very likely that the problem is not related to the development part.
Close.

It was a very mysterious behavior, but it was solved.
After enabling 2-fa verification for my Google account, I now receive SMS.

I don't know what triggers this event.
It 鈥檚 very strange.

Hey Its same here also, my code is working properly but i'm not recieving any SMS
can someone help

I have whole cellular carriers in my country that don't forward the SMS through, and some that only forward through with a delay. SMS is basically a "best effort" thing. Unless you work directly with the carriers in your country and send through an entity that they promise to deliver the messages for, you can't treat SMS as reliable. You must have a backup method.

if you have implemented the testing SMS numbers you can configure in the firebase console and when you use those it works, that's the most you can do in some cases

So if still I want to implement phone auth on react native using expo what should I do ?

Bare Workflow should be fine with this library

Can you please elaborate

https://docs.expo.io/bare/using-expo-client

That explains it better than I can!

Please make sure you are not using the same number you used as default in firebase console, It won't send notification to the same number in the console, try using a different number.

Hi guys, I have some weird issue. Hardcoding and calling functions with testing phone numbers works perfect ( though I still do not receive any sms code ). But when I try to send verification code to my other phone number which is not under testing there is small black line at notification bar that closes immediately as if it received code but it is never shown. Any advice would be helpful.

adb logcat

@mikehardy This is the log that I get from android device.

01-11 09:33:11.690 569 585 E QC-time-services: Receive Passed == base = 13, unit = 1, operation = 2, result = 0
01-11 09:33:11.690 697 896 E QC-time-services: Daemon: Time-services: Waiting to acceptconnection
01-11 09:33:11.690 697 896 E QC-time-services: Daemon: Time-services: Waiting to acceptconnection
01-11 09:33:11.733 700 27870 E ResolverController: No valid NAT64 prefix (387, /0)
01-11 09:33:11.942 8477 32261 E AsyncOperation: operation=attest, opStatusCode=7 [CONTEXT service_id=45 ]
01-11 09:33:11.942 8477 32261 E AsyncOperation: OperationException[Status{statusCode=NETWORK_ERROR, resolution=null}]
01-11 09:33:11.942 8477 32261 E AsyncOperation: at atfl.a(:com.google.android.gms@[email protected] (120400-349456378):2)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at atfl.fR(:com.google.android.gms@[email protected] (120400-349456378):151)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at abbq.run(:com.google.android.gms@[email protected] (120400-349456378):15)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at bpys.run(:com.google.android.gms@[email protected] (120400-349456378):2)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at tku.c(:com.google.android.gms@[email protected] (120400-349456378):6)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at tku.run(:com.google.android.gms@[email protected] (120400-349456378):7)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at tqr.run(:com.google.android.gms@[email protected] (120400-349456378):0)
01-11 09:33:11.942 8477 32261 E AsyncOperation: at java.lang.Thread.run(Thread.java:919)
01-11 09:33:11.943 23379 23379 E zzf : Problem retrieving SafetyNet Token: 7:
01-11 09:33:12.288 23379 27877 E FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with {
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "error": {
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "code": 400,
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "message": "INVALID_CERT_HASH",
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "errors": [
01-11 09:33:12.288 23379 27877 E FirebaseAuth: {
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "message": "INVALID_CERT_HASH",
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "domain": "global",
01-11 09:33:12.288 23379 27877 E FirebaseAuth: "reason": "invalid"
01-11 09:33:12.288 23379 27877 E FirebaseAuth: }
01-11 09:33:12.288 23379 27877 E FirebaseAuth: ]
01-11 09:33:12.288 23379 27877 E FirebaseAuth: }
01-11 09:33:12.288 23379 27877 E FirebaseAuth: }
01-11 09:33:12.288 23379 27877 E FirebaseAuth: 400
01-11 09:33:12.334 23379 23379 E zzf : Failed to get reCAPTCHA token - calling backend without app verification
01-11 09:33:12.380 700 27887 E ResolverController: No valid NAT64 prefix (387, /0)
01-11 09:33:13.642 700 27889 E ResolverController: No valid NAT64 prefix (387, /0)
01-11 09:33:15.648 700 27896 E ResolverController: No valid NAT64 prefix (387, /0)
01-11 09:33:17.653 700 27897 E ResolverController: No valid NAT64 prefix (387, /0)
01-11 09:33:18.287 26069 26241 E msgr.msys: E[N rtchannel]_rt_mqtt_publish_callback(353)=>Failed to publish the request over MQTT. token:c70f5b42-c6db-4e5b-9361-ec843d8c3ba4, category:mcd-sync-data-task-category, requestId:20028, error:Error Domain=mqtt Code=3008
01-11 09:33:18.287 26069 26240 E msgr.msys: E[S sync]_createResponseError(164)=>Network Response c70f5b42-c6db-4e5b-9361-ec843d8c3ba4 contains sync error Error Domain=mqtt Code=3008 - Underlying error (null): Error Domain=mqtt Code=3008
01-11 09:33:18.287 26069 26241 E msgr.msys: E[N rtchannel]_rt_mqtt_publish_callback(353)=>Failed to publish the request over MQTT. token:2e0b3fbf-70dd-4d25-9841-04e78ea3a110, category:mcd-sync-data-task-category, requestId:3941, error:Error Domain=mqtt Code=3008
01-11 09:33:18.290 26069 26240 E msgr.msys: E[S sync]_createResponseError(164)=>Network Response 2e0b3fbf-70dd-4d25-9841-04e78ea3a110 contains sync error Error Domain=mqtt Code=3008 - Underlying error (null): Error Domain=mqtt Code=3008
01-11 09:33:19.589 6029 12066 E BtGatt.GattService: [Landroid.content.pm.ServiceInfo;@af052d1

@mikehardy Quick update, I have found solution for error above. The issue was that I have not correctly copied SHA for my debug project. It was fixed, then I had issue with app crashing, but this solution helped me to overcome that.

Was this page helpful?
0 / 5 - 0 ratings