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

Using custom sentry-native library with Android SDK #1626

Closed
triplef opened this issue Jul 27, 2021 · 7 comments
Closed

Using custom sentry-native library with Android SDK #1626

triplef opened this issue Jul 27, 2021 · 7 comments

Comments

@triplef
Copy link

triplef commented Jul 27, 2021

Our Android app uses both Java and native C/C++ code with Qt, and we’d like to take advantage of the optional Qt integration in sentry-native, which is not enabled for the sentry-native library bundled with the Sentry Android SDK from Maven Central.

Is it possible to use a self-compiled sentry-native library in combination with the sentry-android SDK?

@bruno-garcia
Copy link
Member

@triplef I might be wrong here and @Swatinem can call em out but assuming all there is to it is compiling with the Qt flags, it's probably fine to just replace the libsentry.so in the sentry-android-ndk.aab with your own version since we don't do anything fancy when compiling sentry-native:

cmake_minimum_required(VERSION 3.10)
project(Sentry-Android LANGUAGES C CXX)
# Add sentry-android shared library
add_library(sentry-android SHARED src/main/jni/sentry.c)
# make sure that we build it as a shared lib instead of a static lib
set(BUILD_SHARED_LIBS ON)
set(SENTRY_BUILD_SHARED_LIBS ON)
# Adding sentry-native submodule subdirectory
add_subdirectory(${SENTRY_NATIVE_SRC} sentry_build)
# Link to sentry-native
target_link_libraries(sentry-android PRIVATE
$<BUILD_INTERFACE:sentry::sentry>
)

You could possibly fork this repo, change the CmakeLists we use and build from source. If you choose this route, I suggest sticking to a tagged version of the SDK (i.e: checkout tag 5.0.1 to stay on a proper 'release')

@triplef
Copy link
Author

triplef commented Jul 27, 2021

Thank you for the quick input on this @bruno-garcia!

This sounds like it should work fine, but I'd like to see if there's a way we can keep using the official builds of the Android SDK to keep things simple.

I'm not entirely clear on how linking works with AABs, but would it work to keep using the Android SDK from Maven Central and just link our Qt project against a self-built sentry-native.so with Qt support? We already extracted the native library from the AAB in order to call functions from sentry-native from our native code, so it would be easy to just replace that with a custom build, but I'm unsure which library the linker would end up using.

@marandaneto
Copy link
Contributor

@triplef that makes sense.

SENTRY_INTEGRATION_QT (Default: OFF): Builds the Qt integration, which turns Qt log messages into breadcrumbs.

@Swatinem would be possible to turn this on by default for Android builds? is there any side effect rather than package size ?

@triplef
Copy link
Author

triplef commented Jul 28, 2021

SENTRY_INTEGRATION_QT (Default: OFF): Builds the Qt integration, which turns Qt log messages into breadcrumbs.

@Swatinem would be possible to turn this on by default for Android builds? is there any side effect rather than package size ?

I believe this will require linking against Qt libraries, so that wouldn’t work for the default case, unless there was a way to resolve these symbols at runtime if available. It would definitely be nice if the Android SDK were to support Qt out of the box.

@marandaneto
Copy link
Contributor

last case a pre-compiled package would work too, like sentry-android-qt which does the linking against the Qt libraries, but the package would be added manually along with sentry-android instead of a transitive dependency of sentry-android

@Swatinem
Copy link
Member

As @triplef mentioned, building for Qt by default would mean that the Qt libraries are required at runtime so that is not the way to go.

If you want to continue using the pre-build/packaged version of sentry-native, you can do so, and just vendor/copy-paste the integration into your own code. It is super tiny, and does not depend on any sentry-native internals. All the integration does right now is capture Qt logs as sentry breadcrumbs.

https://github.com/getsentry/sentry-native/blob/master/src/integrations/sentry_integration_qt.cpp

@triplef
Copy link
Author

triplef commented Jul 28, 2021

Ah nice, that seems like the most straightforward solution. Thank you @Swatinem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants