NativeScript / firebase

Modular Firebase đŸ”¥ implementation for NativeScript. Supports both iOS & Android platforms for all Firebase services.
https://docs.nativescript.org/plugins/firebase-core.html
Apache License 2.0
52 stars 46 forks source link

firebase().ui().show crashes on Android with Error: Cannot read properties of undefined (reading 'launch') #217

Closed dlcole closed 1 year ago

dlcole commented 1 year ago

I'm trying to use @nativescript/firebase-ui for phone authentication. I have a plain NativeScript Hello World project, and the only code it contains is the firebase core, messaging, auth, database, and UI plugins, code to initialize firebase and get the device token, and code to invoke firebase-ui for phone authentication:

  import { PhoneProvider } from '@nativescript/firebase-ui';

  firebase()
    .ui()
    .show({ providers: [new PhoneProvider()] })
    .then((result) => {
        console.log(result.user);
        console.log(result.hasCredentialForLinking);
        console.log(result.providerType);
    })
    .catch((error) => {
        console.error('show error:', error);
    });

On Android, I can build successfully, but on execution, receive this error

System.err: An uncaught Exception occurred on "main" thread.
  System.err: tech.govia.newdb: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
  System.err: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

Edit 4/30/2023: Edited to show current error

Here's the package.json contents:

{
  "name": "newdb",
  "main": "app/app.js",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@nativescript/core": "~8.5.0",
    "@nativescript/firebase-auth": "^3.1.0",
    "@nativescript/firebase-core": "^3.1.0",
    "@nativescript/firebase-database": "^3.1.0",
    "@nativescript/firebase-messaging": "^3.1.0",
    "@nativescript/firebase-ui": "^3.1.0",
    "@nativescript/theme": "~3.0.2"
  },
  "devDependencies": {
    "@nativescript/android": "8.5.0",
    "@nativescript/ios": "8.5.2",
    "@nativescript/webpack": "~5.0.14"
  }
}

And the app.gradle contents:

// You can add your native dependencies here
dependencies {
//  implementation 'androidx.multidex:multidex:2.0.1'
}

android {
  compileSdkVersion 33 
  defaultConfig {  
    generatedDensities = []
    applicationId = "tech.govia.newdb" 
    multiDexEnabled true
    minSdkVersion 19
    targetSdkVersion 33
    versionCode 1
    versionName "1.0.0"
  }

  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}
dlcole commented 1 year ago

The FLAG_IMMUTABLE or FLAG_MUTABLE error was resolved by adding this to app.gradle:

implementation 'com.google.android.gms:play-services-auth:20.5.0'

as per this SO post. 20.5.0 is the current latest version.

I get a subsequent "An unknown error occurred" error message on the Enter your phone number screen, but I'll investigate that separately and will close this issue.