irondash / cargokit

Integrate cargo build with flutter plugins and applications.
Other
51 stars 16 forks source link

Missing debug symbols for Android #49

Closed AlienKevin closed 6 months ago

AlienKevin commented 6 months ago

Issue Summary

Using the default config of cargokit with Flutter Rust Bridge V2, I observed that the panic backtrace works well on iOS. However, when I tested on Android, I noticed that the debug symbols are redacted as s.

Issue Details

I tested the panic backtrace using backtrace-rs and sentry-rust's panic monitoring mechanism. Flutter was ran under the debug mode with no modification to cargokit's configurations. I also tested on both a real Android 10 device and a Android 14 simulator. All experiments produced the same result: full trace on iOS but redacted trace on Android. I think this maybe due to missing debug symbols for Android.

Here are the panic backtraces for iOS and Android:

Proposed Changes

  1. Default to bundle debug symbols in dev mode on Android
  2. Offer ways to configure symbol stripping in dev vs release modes.
knopp commented 6 months ago

Cargokit doesn't strip the symbols. Symbols stripping can be configured in Cargo.toml, which is part of your project.

For example: https://github.com/superlistapp/super_native_extensions/blob/main/super_native_extensions/rust/Cargo.toml

If not stripped by cargo, the symbols might also be stripped by gradle when packaging the app

https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/dsl/JniLibsPackagingOptions

AlienKevin commented 5 months ago

Thanks for the pointers. For future people's reference here are the two key steps you need to do:

  1. If you wish to keep debug symbols in release mode, you have to turn on debug in your Rust code's cargo.toml:

    [profile.release]
    debug = true
  2. To keep all debug symbols on Android, you need to add the following lines to your android/app/build.gradle:

    android {
    ..
    packagingOptions {
        jniLibs.keepDebugSymbols += "**/*.so"
    }
    }

    Note: This will keep debug symbols in both debug and release mode for all your native dependencies. You might want to specify only the .so file for your rust library to reduce the bundle size in production. Another thing to note is that you should add this packagingOptions in your app's build.gradle, not in the one in the rust_builder library generated by cargokit.