Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release runtime error when upgrading from 8.9.0 to 8.12.0 without updating io.sentry.android.gradle #2544

Open
jamesncl opened this issue Dec 31, 2024 · 7 comments

Comments

@jamesncl
Copy link

jamesncl commented Dec 31, 2024

Platform

Flutter Mobile Android

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.24.3, on macOS 15.1 24B2083 darwin-arm64, locale en-GB)
• Flutter version 3.24.3 on channel stable at /Users/james/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (4 months ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at /Users/james/Library/Android/sdk
• Platform android-35, build-tools 35.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16C5032a
• CocoaPods version 1.14.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.96.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.1 24B2083
darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.1 24B2083
darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome
131.0.6778.205
! Error: Browsing on the local area network for Test user’s Apple Watch. Ensure the device is
unlocked and discoverable via Bluetooth. (code -27)
! Error: Browsing on the local area network for Test user’s iPhone. Ensure the device is unlocked
and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
• All expected network resources are available.

• No issues found!

Version

8.12.0

Steps to Reproduce

  1. Add sentry_flutter: ^8.9.0 to pubspec.yaml
  2. Add the following configuration to pubspec.yaml:
sentry:
  upload_debug_symbols: true
  upload_source_maps: false
  upload_sources: false
  project: <redacted>
  org: <redacted>
  1. Add id "io.sentry.android.gradle" version "4.11.0" to the plugins section of app build.gradle
  2. The rest of my sentry setup is pretty much vanilla - eg calling SentryFlutter.init on app startup
  3. Build and run the app in release mode - everything works as intended
  4. Upgrade sentry_flutter to 8.12.0 in pubspec.yaml, but do not upgrade io.sentry.android.gradle
  5. Build and run the app in release mode
  6. Observe unhandled exception (only seems to happen in release mode, not debug)

Note that I have not tested which specific version of 'sentry_flutter' is the problem, it could be any version between 8.9.0 and 8.12.0 - sorry I don't have time to investigate this further today

Expected Result

I'm guessing this is due to some incompatibility between flutter_sentry and the Gradle plugin. Ideally this should fail to compile (I'm not sure if that would be possible?), or provide some kind of compile time warning, or failing that a more informative error message. Also, I think there needs to be some kind of breaking change note in the change log on pub.dev. It's quite a nasty one because, for me, it only appeared in my release build, not debug build, so I ended up shipping a broken app to beta testers.

Actual Result

A runtime error in release mode which breaks the app, resulting in blank screen on startup - see below. Strangely, reverting flutter_sentry back to 8.9.0 followed by a flutter clean and rebuild did not seem to resolve the error. Upgrading the Gradle plugin to 4.14.1 did resolve the error.

NoSuchMethodError

No static method addIntegrationToSdkVersion(Ljava/lang/Class;)V in class Lio/sentry/util/k; or its super classes (declaration of 'io.sentry.util.k' appears in /data/app/~~ar5n8jlpWbEKsEs2xmdyoA==/com.chronicinsights-W9merKgO16-lLTU-lG9x0Q==/base.apk!classes2.dex)

io.sentry.android.fragment.FragmentLifecycleIntegration
in register at line 52
io.sentry.Sentry
in init at line 271
io.sentry.Sentry
in init at line 167
io.sentry.android.core.SentryAndroid
in init at line 93
io.sentry.android.core.SentryAndroid
in init
io.sentry.flutter.SentryFlutterPlugin
in initNativeSdk at line 160
io.sentry.flutter.SentryFlutterPlugin
in onMethodCall at line 94
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler
in onMessage at line 267
io.flutter.embedding.engine.dart.DartMessenger
in invokeHandler at line 292
io.flutter.embedding.engine.dart.DartMessenger
in lambda$dispatchMessageToQueue$0 at line 319
io.flutter.embedding.engine.dart.DartMessenger
in $r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo
… er$$InternalSyntheticLambda$1$5dd8b6f7959f08bc8717eff7469e77e06ef5aed51cc0cee17f1e13794798223f$0
in run
android.os.Handler
in handleCallback at line 959
android.os.Handler
in dispatchMessage at line 100
android.os.Looper
in loopOnce at line 232
android.os.Looper
in loop at line 317
android.app.ActivityThread
in main at line 8699
java.lang.reflect.Method
in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller
in run at line 580
com.android.internal.os.ZygoteInit
in main at line 886

Are you willing to submit a PR?

None

@jamesncl
Copy link
Author

There is another issue here in sentry-java which seems to be related, but refers to different versions, and is closed

@vaind
Copy link
Collaborator

vaind commented Dec 31, 2024

@jamesncl
Copy link
Author

I don't believe so. This is my top level build.gradle:

plugins {
    id 'com.google.devtools.ksp' version '1.9.24-1.0.20' apply false
}


allprojects {
    repositories {
        google()
        mavenCentral()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
}

rootProject.buildDir = "../build"
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

And settings.gradle

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    // This is the AGP (Android Gradle Plugin) version:
    id "com.android.application" version "7.4.2" apply false
    // This is the Kotlin version:
    id "org.jetbrains.kotlin.android" version "1.9.24" apply false
    // This is for secrets-gradle-plugin
    id "com.google.android.libraries.mapsplatform.secrets-gradle-plugin" version "2.0.1" apply false
}

include ":app"
include ':app_wearos'
include ':app_wearos_common'
include ':unityLibrary'

This is the plugins block at the top of my app build.gradle:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "kotlin-kapt"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
    // This was added to deobfuscate stack traces in sentry, see https://docs.sentry.io/platforms/android/gradle/
    id "io.sentry.android.gradle" version "4.11.0"
    // This was added so that we can store Places API key and other secrets in secrets.properties
    // using the Gradle secrets plugin, see https://github.com/google/secrets-gradle-plugin
    // It must be AFTER apply plugin: 'com.android.application', see https://github.com/google/secrets-gradle-plugin/issues/62
    id "com.google.android.libraries.mapsplatform.secrets-gradle-plugin"
    id 'com.google.devtools.ksp'
}

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 31, 2024
@vaind
Copy link
Collaborator

vaind commented Jan 1, 2025

I've had a look at the sentry-android-gradle-plugin and it looks like it's adding a dependency on sentry-nadroid by itself, with a version specified in the plugin. This does not work with Flutter because there are internal APIs exposed from the native SDK (sentry-android) to the Flutter SDK (sentry-flutter) and there are breaking changes made between minor versions, since these APIs are only internal and we depend on an exact version here in the flutter SDK. In other words, each Sentry Flutter SDK version requires an exact version of the native SDK, specified in specified flutter/android/build.gradle, e.g. for v8.12.0 it's here :https://github.com/getsentry/sentry-dart/blob/8.12.0/flutter/android/build.gradle#L63

I'd have expected the dependency constraint in sentry-flutter SDK would prevent a build if a different version is specified in the app but my Gradle knowledge is spotty.
@romtsn do you have any idea how we can enforce that even when users use the sentry-android-gradle-plugin or if they specify a dependency on sentry-android manually, the SDK version must match what's defined (and included) from the sentry-flutter plugin?

@romtsn
Copy link
Member

romtsn commented Jan 1, 2025

this particular issue was an oversight from our side (should've been a major bump since we removed a public API method), but we call it out now to align versions of sentry-android and integrations to the same one to resolve it.

In general we should recommend disabling auto-installation when the gradle plugin is used for the hybrid SDKs case, like we do in the React Native docs, to avoid this situation altogether.

Alternatively we could try to set up gradle dependency constraints for the sentry-android dependency.

@vaind vaind added the docs label Jan 2, 2025
@buenaflor buenaflor moved this from Needs Discussion to Backlog in Mobile & Cross Platform SDK Jan 2, 2025
@buenaflor
Copy link
Contributor

In general we should recommend disabling auto-installation when the gradle plugin is used for the hybrid SDKs case, like we do in the React Native docs, to avoid this situation altogether.

yup we need to document this better in the flutter docs

@buenaflor buenaflor moved this from Backlog to Todo in Mobile & Cross Platform SDK Jan 2, 2025
@vaind
Copy link
Collaborator

vaind commented Jan 2, 2025

Setting up a dependency constraint, or specifying the dependency as a [strict version] (https://docs.gradle.org/current/userguide/dependency_versions.html#sec:strict-version) in the flutter SDK sounds like a useful thing to avoid these issues (I remember responding to another similar issue with an android native version mismatch, recently). Any ideas why that could be problematic/breaking for some users (with no workaround)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Todo
Development

No branches or pull requests

4 participants