Search code examples
androidandroid-studionativescriptnativescript-angularsentry

Android Sentry is Undefined after providing DSN


I just recently added Sentry into my Android application. The App is built using Nativescript but trying to release it on the Google Play store. I added the implementation of android sentry in my build.gradle file, and added the correct meta data in Android Manifest.

However, everytime I open the app, it stops working with this error.

    E/JS: [SentryAngular - SentryErrorHandler] TypeError: Cannot read property 'Sentry' of undefined
    E/JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'Sentry' of undefined
        TypeError: Cannot read property 'Sentry' of undefined
            at Function.e.captureException (file:///data/user/0/com.rowforgellc.rowforge/files/app/vendor.js:35420:16)
            at Function.e.captureException (file:///data/user/0/com.rowforgellc.rowforge/files/app/bundle.js:4856:43)
            at e.<anonymous> (file:///data/user/0/com.rowforgellc.rowforge/files/app/bundle.js:3547:16)
            at file:///data/user/0/com.rowforgellc.rowforge/files/app/bundle.js:3536:14
            at Object.throw (file:///data/user/0/com.rowforgellc.rowforge/files/app/bundle.js:3538:40)
            at s (file:///data/user/0/com.rowforgellc.rowforge/files/app/bundle.js:3512:294)
            at e.invoke (file:///data/user/0/com.rowforgellc.rowforge/files/app/vendor.js:19256:137)
            at Object.onInvoke (file:///data/user/0/com.rowforgellc.rowforge/files/app/vendor.js:13832:10)
            at e.invoke (file:///data/user/0/com.rowforgellc.rowforge/files/app/vendor.js:19256:77)
            at t.run (file:...

Here is my AndroidManifest.xml

<application>
...
  <meta-data android:name="io.sentry.dsn" android:value="https://<DSN_HERE>.ingest.sentry.io/5339956" />

...
</application>

I don't have any idea of how to debug this. Much help would be appreciated.

UPDATE: FIXED

Just got this to work actually. My nativescript portion was already handling the Sentry with Javascript, but I had to get rid of the implementation SDK in the Build.gradle. Seems like it was conflicting with the javascript SDK.


Solution

  • You've added Sentry Android SDK to your gradle file as a dependency.

    This gives you the Sentry SDK for Android. You can use it with Java, Kotlin and even C/C++ since it supports NDK. It'll capture Uncaught Exceptions, ANR, native crashes from native libraries, etc.

    But this SDK is unaware of the JavaScript (NativeScript) layer you have on top.

    Sentry has a package for React Native which is based on the JavaScript SDK on top of the Android and iOS SDKs, but that won't help you with NativeScript.

    That said, I don't believe Sentry has support to NativeScript at this point so you'd need to either invoke the native layer to capture errors via the native SDK, or attempt to create a wraps similar to the React Native SDK mentioned above.