elastic / apm-agent-android

Elastic APM Android Agent
Apache License 2.0
21 stars 6 forks source link

I'm getting the following crash on Android 11 and 12 #338

Open alex-oczkowski-arq-group opened 3 months ago

alex-oczkowski-arq-group commented 3 months ago

Hi, I've been getting the following crash with Android versions 11 and 12

java.lang.VerifyError: Verifier rejected class io.opentelemetry.sdk.metrics.SdkDoubleGauge$SdkDoubleGaugeBuilder: io.opentelemetry.api.incubator.metrics.DoubleGauge io.opentelemetry.sdk.metrics.SdkDoubleGauge$SdkDoubleGaugeBuilder.build() failed to verify: io.opentelemetry.api.incubator.metrics.DoubleGauge io.opentelemetry.sdk.metrics.SdkDoubleGauge$SdkDoubleGaugeBuilder.build(): [0x4]  can't resolve returned type 'Unresolved Reference: io.opentelemetry.api.incubator.metrics.DoubleGauge' or 'Unresolved Reference: io.opentelemetry.sdk.metrics.SdkDoubleGauge' (declaration of 'io.opentelemetry.sdk.metrics.SdkDoubleGauge$SdkDoubleGaugeBuilder' appears in /data/app/~~OaE29eflqDJYvUe5K7KmLQ==/com.hummloan.au.sit-TUsSobuj2avVjcLsdx-nJw==/base.apk!classes7.dex)
                                                                                                        at io.opentelemetry.sdk.metrics.SdkMeter.gaugeBuilder(SdkMeter.java:111)
                                                                                                        at co.elastic.apm.android.sdk.internal.features.launchtime.LaunchTimeApplicationListener.sendAppLaunchTimeMetric(LaunchTimeApplicationListener.java:47)
                                                                                                        at co.elastic.apm.android.sdk.internal.features.launchtime.LaunchTimeApplicationListener.onApplicationForegrounded(LaunchTimeApplicationListener.java:39)
                                                                                                        at io.opentelemetry.android.ApplicationStateWatcher.onActivityStarted(ApplicationStateWatcher.java:27)
                                                                                                        at android.app.Application.dispatchActivityStarted(Application.java:386)
                                                                                                        at android.app.Activity.dispatchActivityStarted(Activity.java:1366)
                                                                                                        at android.app.Activity.onStart(Activity.java:1878)
                                                                                                        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:344)
                                                                                                        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
                                                                                                        at au.com.flexirent.humm.views.landing.SplashActivity.onStart(SplashActivity.kt:67)
                                                                                                        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1455)
                                                                                                        at android.app.Activity.performStart(Activity.java:8076)
                                                                                                        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3660)
                                                                                                        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
                                                                                                        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
                                                                                                        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:7839)
                                                                                                        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:1003)

My code to initialise Elastic is

val configuration = ElasticApmConfiguration.builder()
            .setServiceName(BuildConfig.ELASTIC_SERVICE_NAME)
            .setServiceVersion(BuildConfig.VERSION_NAME)
            .setDeploymentEnvironment(BuildConfig.ELASTIC_DEPLOYMENT_ENVIRONMENT)
            .build()

val connectivity = Connectivity.simple(BuildConfig.ELASTIC_SERVER_URL)
ElasticApmAgent.initialize(this, configuration, connectivity)

which is happening just after the Application onCreate super call.

Commenting out the Elastic monitoring initialisation method above prevents the crash.

On the Android versions mentioned below, there are no issues and everything is coming through as expected.

Any ideas what could be the issue?

Update: Testing results on my Pixel 3a emulator for different Android versions (API level) Works: 34, 33, 29, 28
 Not working: 32, 31, 30

LikeTheSalad commented 3 months ago

Hi @alex-oczkowski-arq-group

Thank you for the details, I would like to confirm a couple of things. Are you using our plugin? Or are you setting up the agent manually? And also please let me know which version of the agent you are using.

alex-oczkowski-arq-group commented 3 months ago

I am setting up the agent manually. The version is

implementation 'co.elastic.apm:android-sdk:0.17.0'

LikeTheSalad commented 3 months ago

Hi @alex-oczkowski-arq-group

Thank you for your patience. I've tested version 0.17.0 on emulators with API 32, 31, and 30 and I couldn't reproduce this issue.

Based on the stacktrace you've shared, it seems like some OTel classes might be missing due to the part that reads:

Unresolved Reference: io.opentelemetry.api.incubator.metrics.DoubleGauge

The reason why I mentioned if you were using our plugin is because our plugin does bytecode manipulation, which is the kind of action that might cause the issue that you mentioned, however, since that's not the case, then another reason I could think of might be that a tool like R8 could be removing said classes, although it shouldn't be the case as we've added proguard rules to prevent it from happening to OTel classes.

Based on the above, there are a couple of things I could recommend trying:

If none of the above works, the only thing left would be if you can provide a demo app where this issue is reproducible, so that I can take a more detailed look at it.