capawesome-team / capacitor-firebase

⚡️ Firebase plugins for Capacitor. Supports Android, iOS and the Web.
https://capawesome.io/plugins/firebase/
Apache License 2.0
369 stars 96 forks source link

bug: #456

Closed sseppo closed 10 months ago

sseppo commented 10 months ago

Plugin(s)

Did you test the latest version?

Platform(s)

Current behavior

App crashses on Android if @capacitor-firebase/authentication is installed in the project. If I uninstall it the app starts. If I install it again npm i @capacitor-firebase/authentication the app crashes on start. The app is React app.

After that I tried to clone and run the demo as instructed here https://github.com/robingenz/capacitor-firebase-authentication-demo

in order to see if it was something related only to this project, but when running npx ionic cap run android it failed with

× Running Gradle build - failed! [capacitor] [error] [capacitor] FAILURE: Build completed with 2 failures. [capacitor] [capacitor] 1: Task failed with an exception. [capacitor] ----------- [capacitor] * Where: [capacitor] Build file 'C:\wwwroot\test3\fireauth\capacitor-firebase-authentication-demo\android\app\build.gradle' line: 5 [capacitor] [capacitor] * What went wrong: [capacitor] A problem occurred evaluating project ':app'. [capacitor] > C:\wwwroot\test3\fireauth\capacitor-firebase-authentication-demo\android\keystore.properties (The system cannot find the file specified) [capacitor] [capacitor] * Try: [capacitor] > Run with --stacktrace option to get the stack trace. [capacitor] > Run with --info or --debug option to get more log output. [capacitor] > Run with --scan to get full insights. [capacitor] ============================================================================== [capacitor] [capacitor] 2: Task failed with an exception. [capacitor] ----------- [capacitor] * What went wrong: [capacitor] A problem occurred configuring project ':app'. [capacitor] > compileSdkVersion is not specified. Please add it to build.gradle [capacitor] [capacitor] * Try: [capacitor] > Run with --stacktrace option to get the stack trace. [capacitor] > Run with --info or --debug option to get more log output. [capacitor] > Run with --scan to get full insights.

Expected behavior

For app to start when @capacitor-firebase/authentication is installed

Reproduction

https://github.com/sseppo/authtest.git

Steps to reproduce

  1. Clone / download the git
  2. run npx cap run android
  3. The app starts but stops immdeately. If started again from the installed applications, same happens.

Antother way:

  1. cd to some suitable folder
  2. Run: ionic start authtest blank --type react (and if you like to test now: ionic serve)
  3. Run: npm install @capacitor/android
  4. Run: npx cap add android (and if you like to test now: ionic build, npx cap open android, npx cap run android)
  5. Run: npm i @capacitor-firebase/authentication
  6. Run: ionic build
  7. Run: npx cap sync
  8. Run: ionic cap update
  9. Run: npx cap run android -> crash when app starts

Other information

from package.json: "dependencies": { "@capacitor-firebase/authentication": "^5.1.0", "@capacitor/android": "^5.5.0", "@capacitor/app": "5.0.6", "@capacitor/core": "5.5.0", "@capacitor/haptics": "5.0.6", "@capacitor/ios": "^5.5.0", "@capacitor/keyboard": "5.0.6", "@capacitor/status-bar": "5.0.6", "@ionic/react": "^7.0.0", "@ionic/react-router": "^7.0.0", "@types/react-router": "^5.1.20", "@types/react-router-dom": "^5.3.3", "ionicons": "^7.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router": "^5.3.4", "react-router-dom": "^5.3.4" }, "devDependencies": { "@capacitor/cli": "5.5.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.3", "@types/react": "^18.0.27", "@types/react-dom": "^18.0.10", "@vitejs/plugin-legacy": "^4.0.2", "@vitejs/plugin-react": "^4.0.1", "cypress": "^12.7.0", "eslint": "^8.35.0", "eslint-plugin-react": "^7.32.2", "jsdom": "^22.1.0", "typescript": "^5.1.6", "vite": "^4.3.9", "vitest": "^0.32.2" },

Capacitor doctor

Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 5.5.0 @capacitor/core: 5.5.0 @capacitor/android: 5.5.0 @capacitor/ios: 5.5.0

Installed Dependencies:

@capacitor/cli: 5.5.0 @capacitor/android: 5.5.0 @capacitor/core: 5.5.0 @capacitor/ios: 5.5.0

[success] Android looking great! 👌

Before submitting

robingenz commented 10 months ago

You may not only install the plugin, you must also add Firebase and configure the plugin correctly, see Installation.

After that I tried to clone and run the demo as instructed here robingenz/capacitor-firebase-authentication-demo

in order to see if it was something related only to this project, but when running npx ionic cap run android it failed with

Please take a look at this comment.

sseppo commented 10 months ago

Hi, thanks I forgot to add firebase to miminun reproduction package. I added it and updated the git also. Still same results - app closes as soon as it opens.

Steps I added:

  1. npm i firebase
  2. added the needed lines for capacitor.config.ts (array just for google.com for testing purposes)
  3. Made the project at firebase console: added Android project with SHA1, downloaded and added the google-services.json, added Authentication and added Google as provider
  4. Added the required parts to build.gradle -files
  5. Re-built, re-synced and re-opened/run the project.

Also added there the keystore as mentioned in the comment you linked. But didn't help the issue.

As for the demo project, adding the keystore there did not help it either. I could copy-paste the error from that to here, but I guess that is for another thread, as it is anyway different project.

robingenz commented 10 months ago

Please share the exception message from Logcat.

sseppo commented 10 months ago

Hopefully not too messy :) Seems the tool here does not recognize this as code block, but maybe it is just the preview.

2023-10-13 18:41:49.228  4359-4359  AndroidRuntime io.ionic.starter E  FATAL EXCEPTION: main

Process: io.ionic.starter, PID: 4359
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/signin/GoogleSignIn;
at io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.GoogleAuthProviderHandler.buildGoogleSignInClient(GoogleAuthProviderHandler.java:119)
at io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.GoogleAuthProviderHandler.buildGoogleSignInClient(GoogleAuthProviderHandler.java:97)
at io.capawesome.capacitorjs.plugins.firebase.authentication.handlers.GoogleAuthProviderHandler.<init>(GoogleAuthProviderHandler.java:35)
at io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthentication.initAuthProviderHandlers(FirebaseAuthentication.java:820)
at io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthentication.<init>(FirebaseAuthentication.java:67)
at io.capawesome.capacitorjs.plugins.firebase.authentication.FirebaseAuthenticationPlugin.load(FirebaseAuthenticationPlugin.java:65)
at com.getcapacitor.PluginHandle.loadInstance(PluginHandle.java:115)
at com.getcapacitor.PluginHandle.load(PluginHandle.java:105)
at com.getcapacitor.PluginHandle.<init>(PluginHandle.java:65)
at com.getcapacitor.Bridge.registerPlugin(Bridge.java:644)
at com.getcapacitor.Bridge.registerAllPlugins(Bridge.java:600)
at com.getcapacitor.Bridge.<init>(Bridge.java:215)
at com.getcapacitor.Bridge.<init>(Unknown Source:0)
at com.getcapacitor.Bridge$Builder.create(Bridge.java:1519)
at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:42)
at com.getcapacitor.BridgeActivity.onCreate(BridgeActivity.java:36)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.signin.GoogleSignIn" on path: DexPathList[[zip file "/data/app/~~ovqG0IZoz_v7N-JyKZls7w==/io.ionic.starter-Bj9PmE7N3tCE55CXlO8OYg==/base.apk"],nativeLibraryDirectories=[/data/app/~~ovqG0IZoz_v7N-JyKZls7w==/io.ionic.starter-Bj9PmE7N3tCE55CXlO8OYg==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

2023-10-13 18:41:49.270  4359-4359  Process io.ionic.starter I  Sending signal. PID: 4359 SIG: 9
---------------------------- PROCESS ENDED (4359) for package io.ionic.starter ----------------------------
robingenz commented 10 months ago

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/auth/api/signin/GoogleSignIn;

You did not follow the installation instructions for Google Sign-In correctly, see https://github.com/capawesome-team/capacitor-firebase/blob/main/packages/authentication/docs/setup-google.md.

  1. Add the following project variable to your variables.gradle file (usually android/variables.gradle):
    ext {
    +    rgcfaIncludeGoogle = true
    }

You seem to be missing this step.

sseppo commented 10 months ago

Thanks @robingenz ! I had that in the app I faced the problem in the first place, but for some reason forgot it from the miminum version showing the problem. It worked after that, or at least did not crash anymore. And for some reason - without really changing anything, it similarly worked for the first app where I faced it first. There is still things to figure out like how to connect it to auth (getAuth() or initializeAuth() ) using the firebase configs but that's not anymore issue of this thread and likely just requires studying capawesome -docs.

Thanks for help and good product!