getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.16k stars 435 forks source link

Misleading error NoSuchMethodError: No virtual method addIntegrationToSdkVersion()V in class Lio/sentry/android/fragment/FragmentLifecycleIntegration #3847

Closed danielesegato closed 2 weeks ago

danielesegato commented 3 weeks ago

Integration

sentry-android

Build System

Gradle

AGP Version

8.7.2

Proguard

Enabled

Version

7.16.0

Steps to Reproduce

  1. Update Sentry version without updating Sentry android plugin
  2. Run the app

The setup:

[versions]
sentry-io = "7.16.0"
sentry-io-plugin = "3.5.0" # instead of last 4.13.0

[libraries]
sentry-io-android = { module = "io.sentry:sentry-android", version.ref = "sentry-io" }
sentry-io-timber = { module = "io.sentry:sentry-android-timber", version.ref = "sentry-io" }

[plugins]
sentry-io = { id = "io.sentry.android.gradle", version.ref = "sentry-io-plugin" }

Configure sentry in the Android Application


    SentryAndroid.init(applicationContext) { options ->
        options.addIntegration(
            SentryTimberIntegration(
                minEventLevel = SentryLevel.ERROR,
            ),
        )
        options.isDebug = isDebug
        options.environment = environment
    }

Add configuration in the manifest:

        <!-- Required: set your sentry.io project identifier (DSN) -->
        <meta-data
            android:name="io.sentry.dsn"
            android:value="https://[redacted].ingest.sentry.io/[redacted]" />

        <!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) -->
        <meta-data
            android:name="io.sentry.traces.user-interaction.enable"
            android:value="true" />
        <!-- enable screenshot for crashes -->
        <meta-data
            android:name="io.sentry.attach-screenshot"
            android:value="true" />
        <!-- enable view hierarchy for crashes -->
        <meta-data
            android:name="io.sentry.attach-view-hierarchy"
            android:value="true" />

        <!-- enable the performance API by setting a sample-rate, adjust in production env -->
        <meta-data
            android:name="io.sentry.traces.sample-rate"
            android:value="1.0" />
        <!-- enable profiling when starting transactions, adjust in production env -->
        <meta-data
            android:name="io.sentry.traces.profiling.sample-rate"
            android:value="1.0" />

Add the sentry.properties file

defaults.project=[redacted]
defaults.org=[redacted]

Run the app

additional information: it used to work, I bumped up libraries versions and got this issue.

These are the relevant changes:

Expected Result

Either the app starts or the error mention incompatible plugin version.

Actual Result

The app crashes with an error that has nothing pointing to the plugin incompatibility being an issue

java.lang.NoSuchMethodError: No virtual method addIntegrationToSdkVersion()V in class Lio/sentry/android/fragment/FragmentLifecycleIntegration; or its super classes (declaration of 'io.sentry.android.fragment.FragmentLifecycleIntegration' appears in /data/app/~~ftLzJZBpcPqu7RoxikSkZw==/com.solongevity.app.dev.debug-dGWYg34RfMvRqAi4gFx4Og==/base.apk!classes13.dex)
    at io.sentry.android.fragment.FragmentLifecycleIntegration.register(FragmentLifecycleIntegration.kt:51)
    at io.sentry.Sentry.init(Sentry.java:271)
    at io.sentry.Sentry.init(Sentry.java:167)
    at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:93)
    at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:64)
    at io.sentry.android.core.SentryInitProvider.onCreate(SentryInitProvider.java:25)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
    at io.sentry.android.core.SentryInitProvider.attachInfo(SentryInitProvider.java:43)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7488)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6999)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6770)
    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7898)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
markushi commented 2 weeks ago

@danielesegato thanks for letting us know. Yeah, this binary incompatibility bug unfortunately slipped in in the 7.16.0 release. It only occurs if the sentry module versions are not in sync (e.g. sentry-android and sentry-android-fragment having different versions).

We've added it as a breaking change note to 7.16.0: https://github.com/getsentry/sentry-java/releases/tag/7.16.0

You can work around this by configuring the Sentry Android Gradle Plugin to use a specific version of the Sentry Android SDK:

sentry {
    autoInstallation {
        enabled = true
        sentryVersion = "7.16.0"
    }
}
matinzd commented 6 days ago

The method is still in use in sentry-okhttp:

https://github.com/getsentry/sentry-java/blob/main/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt#L57

romtsn commented 5 days ago

@matinzd it's a different method with different signature (accepts a String as an argument), and this is the one that replaced the method in question.

matinzd commented 5 days ago

Ah right. I didn't look at the method signatures.