sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

CRASH: java.lang.NoClassDefFoundError: io.sentry.protocol.Contexts

Open SerggioZS opened this issue 1 year ago • 10 comments

Integration

sentry-android

Build System

Gradle

AGP Version

8.3.0

Proguard

Enabled

Version

7.5.0

Steps to Reproduce

When I use the Sentry Gradle plugin id "io.sentry.android.gradle" version "4.3.1" the app crashes at launch with the stacktrace: java.lang.NoClassDefFoundError: io.sentry.protocol.Contexts at io.sentry.JsonSerializer.<init>(JsonSerializer.java:74) at io.sentry.SentryOptions.<init>(SentryOptions.java:121) at io.sentry.SentryOptions.empty(SentryOptions.java:2409) at io.sentry.NoOpHub.<init>(NoOpHub.java:16) at io.sentry.NoOpHub.<clinit>(NoOpHub.java:14) at io.sentry.Sentry.<clinit>(Sentry.java:48) at io.sentry.HubAdapter.getTransaction(HubAdapter.java:230) at io.sentry.instrumentation.file.FileIOSpanManager.startSpan(FileIOSpanManager.java:32) at io.sentry.instrumentation.file.SentryFileOutputStream.init(SentryFileOutputStream.java:73) at io.sentry.instrumentation.file.SentryFileOutputStream.access$000(SentryFileOutputStream.java:21) at io.sentry.instrumentation.file.SentryFileOutputStream$Factory.create(SentryFileOutputStream.java:148) at androidx.multidex.MultiDexExtractor.extract(MultiDexExtractor.java:385) at androidx.multidex.MultiDexExtractor.performExtractions(MultiDexExtractor.java:272) at androidx.multidex.MultiDexExtractor.load(MultiDexExtractor.java:152) at androidx.multidex.MultiDex.doInstallation(MultiDex.java:245) at androidx.multidex.MultiDex.install(MultiDex.java:113) at androidx.multidex.MultiDexApplication.attachBaseContext(MultiDexApplication.java:39) at pt.zonesoft.zsposmobile.ZSPosMobile.attachBaseContext(ZSPosMobile.kt:95) at android.app.Application.attach(Application.java:181) at android.app.Instrumentation.newApplication(Instrumentation.java:991) at android.app.Instrumentation.newApplication(Instrumentation.java:975) at android.app.LoadedApk.makeApplication(LoadedApk.java:511) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4317) at android.app.ActivityThread.access$1500(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

Does not crash when using the dependencies via implementation: implementation platform('io.sentry:sentry-bom:7.5.0') implementation('io.sentry:sentry-android') implementation('io.sentry:sentry-android-fragment')

This happens on android 4.4, I have no idea why this is happenning. Tested the same implementation, with the same dependencies in a sample project and it does not crash. This is very odd.

Expected Result

No crash.

Actual Result

CRASH!

SerggioZS avatar Mar 05 '24 16:03 SerggioZS

Looks like enabling desugaring causes the issue on android 4.4

coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

SerggioZS avatar Mar 05 '24 18:03 SerggioZS

@SerggioZS thanks for reporting! Just to confirm my understanding: It works for you when desugaring is disabled, but stops working once desugaring is enabled?

Do you set any source/target compat flags in your app module? E.g.

configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

markushi avatar Mar 06 '24 07:03 markushi

Hi @markushi the project is setup with this flags:

compileOptions {
        coreLibraryDesugaringEnabled true
        targetCompatibility JavaVersion.VERSION_11
        sourceCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }

SerggioZS avatar Mar 06 '24 09:03 SerggioZS

Thanks for getting back! This sounds like a multi-dex issue, we have some docs around this topic on how to resolve this issue: https://docs.sentry.io/platforms/android/configuration/multi-dex/

Could you give this a try?

markushi avatar Mar 06 '24 14:03 markushi

Hi Thanks for the reply.

Yes, I've tested adding the keep rules to proguard and multidex but the app still crashes.

If the implementation of sentry using the dependencies block is the same as using the gradle plugin and doesn't create any disadvantages then it's all good.

    implementation platform('io.sentry:sentry-bom:7.5.0')
    implementation('io.sentry:sentry-android')
    implementation('io.sentry:sentry-android-fragment')

SerggioZS avatar Mar 06 '24 14:03 SerggioZS

@SerggioZS yes, when it comes to dependencies there should be no difference between using our gradle plugin and manually specifying the dependencies like you did above.

This still sounds a bit weird, maybe there's something wrong with dependency resolution.

Could you please:

  1. Just use gradle plugin (without specifying the dependencies manually)
  2. Retrieve the app dependencies, e.g. via
./gradlew :app:dependencies
  1. Share the relevant output (only the io.sentry.* modules) here?

markushi avatar Mar 13 '24 09:03 markushi

Hey @SerggioZS , do you have an update for us?

markushi avatar Mar 20 '24 13:03 markushi

Hi @markushi

Here is the full dependencies.

sentry_deps.txt

I can send you the sample project If you want to test.

SerggioZS avatar Mar 20 '24 15:03 SerggioZS

@SerggioZS yes, a reproducible example would be very useful! Either attach the sample to the ticket, or in case of PII concerns send it to [email protected]

markushi avatar Mar 21 '24 07:03 markushi

Hi @markushi here is the sample in a zip:

SentryCrashTest.zip 112kb

SerggioZS avatar Mar 21 '24 10:03 SerggioZS