EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

Help with Crashlytics #877

Open carrbrpoa opened 5 years ago

carrbrpoa commented 5 years ago

Hello Today I tried the latest version of nativescript-plugin-firebase for the new Crashlytics in my "old" NS 3.4.2 project for Android but wasn't able to force a crash send report with this code (which I did with old reporting tool):

firebase.sendCrashLog({
      message: "Hey, I was logged!",
      showInConsole: true
    }).then(
        function () {
          console.log('ok crash');
        },
        function (error) {
            console.log(error);
            console.log('nok');
        }
    );

What I see in console:

JS: Make sure firebase-crash is in the plugin's include.gradle
JS: nok

Also tried with...

...
declare const Crashlytics: any;
...
Crashlytics.getInstance().crash();
...

... in main.ts, which throws an Crashlytics is not defined error.

Any ideas?

My package.json: https://gist.github.com/carrbrpoa/fad3b9e9414a28002e157f018b8c9ada

Thanks in advance!

carrbrpoa commented 5 years ago

Then I tried throw new java.lang.Exception("Forced an exception."); from some Page, but nothing is shown in Firebase console. Does it take some hours?

NickIliev commented 5 years ago

@carrbrpoa during the initial installation of nativescript-plugin-firebase the plugin is usually asking what functionalities you want to use and if you want to store them in a file called firebase.nativescript.json (like this one). If you are using this file make sure that the crashlytics key has a true value and then delete _nodemodules and platform folders and run npm i and rebuild the app. If you are not using the file, then simply delete _nodemodules and platform folders and follow the interactive instructions from the nativescript-plugin-firebase (during the npm i)

carrbrpoa commented 5 years ago

Hey @NickIliev!

I do use the file, did as you suggested but doesn't seem to work:

I deleted _nodemodules and platform folders (not hooks folder). Then: $> npm install -ddd $> tns build android --bundle $> tns run android --bundle

After last command conclusion, the app didn't run. I see in console (idk if it's related):

Found peer TypeScript 2.4.2
ActivityManager: Start proc 837:br.my.app/u0a594 for activity br.my.app/com.tns.NativeScriptActivity
System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/br.my.app/shared_prefs/com.crashlytics.sdk.android:answers:settings.
xml.bak
System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/br.my.app/shared_prefs/com.google.android.gms.measurement.prefs.xml.
bak
ActivityManager: removeProcessNameLocked mProcessNames.remove pid=837 ,hash=3587653 ,name=br.my.app
ActivityManager: Process br.my.app (pid 837)(adj 1) has died(28,457)

At this point, I just edited any file, hit save and waited for the automagic build and run to happen again. Saw some sounds good things in console:

...
Webpack compilation complete.
Project successfully prepared (Android)
Executing after-prepare hook from C:\Android\Projetos\MyApp\hooks\after-prepare\firebase-build-gradle.js
Configure firebase
Executing after-prepare hook from C:\Android\Projetos\MyApp\hooks\after-prepare\firebase-copy-google-services.js
Copy C:\Android\Projetos\MyApp\app\App_Resources\Android\google-services.json to C:\Android\Projetos\MyApp\platforms\android\app\google-services.json.
Executing after-prepare hook from C:\Android\Projetos\MyApp\hooks\after-prepare\nativescript-dev-webpack.js
Executing after-prepare hook from C:\Android\Projetos\MyApp\hooks\after-prepare\nativescript-plugin-firebase.js
Building project...
Gradle build...
...

And the app finally did run. Again, in console I see that same JS: Make sure firebase-crash is in the plugin's include.gradle error (idk if it's because I'm trying something specific to the old crash reporting tool or not) and my button that forces the error throws a JS: ERROR Error: Uncaught (in promise): java.lang.Exception: Forced an exception. in console, but I don't see nothing in Firebase Console - still shows zero events.

NickIliev commented 5 years ago

What do you mean bu e I'm trying something specific to the old crash reporting tool or not) - you should use only one of both as quoted from the plugin's readme:

Note that if you want to use Crashlytics, make sure your firebase.nativescript.json file has "crashlytics": true and "crash_reporting": false, then remove the platforms folder so these changes are picked up.

carrbrpoa commented 5 years ago

Sorry, I mean I'm trying the following code:

firebase.sendCrashLog({
      message: "Hey, I was logged!",
      showInConsole: true
    }).then(
        function () {
          console.log('ok crash');
        },
        function (error) {
            console.log(error);
            console.log('nok');
        }
    );

, which throws that JS: Make sure firebase-crash is in the plugin's include.gradle in console plus the throw new java.lang.Exception("Forced an exception."); line somewhere in app.

Btw, here is my firebase.nativescript.json:

{
    "using_ios": false,
    "using_android": true,
    "firestore": false,
    "realtimedb": false,
    "remote_config": false,
    "messaging": false,
    "crashlytics": true,
    "crash_reporting": false,
    "storage": false,
    "facebook_auth": false,
    "google_auth": false,
    "admob": false,
    "invites": false,
    "ml_kit": false
}
carrbrpoa commented 5 years ago

I think it is working now. Did a release build and a true (non forced) fatal exception happened, being logged in Crashlytics.

jacopo69 commented 5 years ago

@carrbrpoa I'm in the same situation and I tried to do a build release as you suggested but nothing has been logged in Crashlytics neither any error raised. Did you insert any specific meta-data in AndroidManifest.xml or do a particular configuration in Firebase console?

carrbrpoa commented 5 years ago

Hey @jacopo69, I didn't need extra configurations. Nuked the app folder and changed to build for release. Firebase Console was kept the way it was before. Just needed to pay attention to the firebase.nativescript.json file. What currently is left is the fact that I didn't manage to force an exception, but I see "true failures" being logged to Firebase Console. PS: Before all that, I used to have a fixed version of nativescript-plugin-firebase in my package.json. Now I let npm get the latest version.

adekunle11 commented 4 years ago

Hello, please this plugin is making app crash when itest it on a real device, it wasn't like that before. Now my app stops working whenever i run it.