diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index da2d0adb2f..5e0bfaa102 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -98,7 +98,7 @@ jobs: - name: Download sentry libs run: | mkdir /tmp/sentry-android-ndk - wget https://repo1.maven.org/maven2/io/sentry/sentry-android-ndk/5.7.4/sentry-android-ndk-5.7.4.aar -O /tmp/sentry.zip + wget https://repo1.maven.org/maven2/io/sentry/sentry-android-ndk/6.13.1/sentry-android-ndk-6.13.1.aar -O /tmp/sentry.zip unzip /tmp/sentry.zip -d /tmp/sentry-android-ndk - name: 🌱 Update ndk @@ -138,7 +138,10 @@ jobs: -D APP_ICON="${APP_ICON}" \ -D APP_NAME="${APP_NAME}" \ -D NUGET_USERNAME=opengisch \ - -D NUGET_TOKEN=${{ secrets.GITHUB_TOKEN }} + -D NUGET_TOKEN=${{ secrets.GITHUB_TOKEN }} \ + -D SENTRY_DSN=${{ secrets.SENTRY_DSN }} \ + -D SENTRY_ENV="${APP_ENV}" \ + -D SENTRY_IMPORT_PREFIX=/tmp/sentry-android-ndk/jni - name: 📑 Upload Dep Build Logs uses: actions/upload-artifact@v3 diff --git a/platform/android/build.gradle.in b/platform/android/build.gradle.in index 11ee96deed..806909ce4d 100644 --- a/platform/android/build.gradle.in +++ b/platform/android/build.gradle.in @@ -98,16 +98,10 @@ android { } } } - - /* For Sentry */ - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } } // Add Sentry's SDK as a dependency. dependencies { - implementation 'io.sentry:sentry-android:5.7.4' + implementation 'io.sentry:sentry-android:6.13.1' } diff --git a/src/sentry/CMakeLists.txt b/src/sentry/CMakeLists.txt index 0160f0f370..daa30153c7 100644 --- a/src/sentry/CMakeLists.txt +++ b/src/sentry/CMakeLists.txt @@ -19,8 +19,12 @@ endif() target_link_libraries(qfield_sentry PRIVATE ${QT_PKG}::Core) if(ANDROID) - target_link_libraries(qfield_sentry PRIVATE android log - ${QT_PKG}::AndroidExtras) + if(BUILD_WITH_QT6) + target_link_libraries(qfield_sentry PRIVATE Qt6::CorePrivate) + else() + target_link_libraries(qfield_sentry PRIVATE ${QT_PKG}::AndroidExtras) + endif() + target_link_libraries(qfield_sentry PRIVATE android log) endif() target_include_directories(qfield_sentry PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/sentry/sentry_classic.cpp b/src/sentry/sentry_classic.cpp index 3619b086b3..e0fa0798a1 100644 --- a/src/sentry/sentry_classic.cpp +++ b/src/sentry/sentry_classic.cpp @@ -23,10 +23,44 @@ #include #ifdef ANDROID +#include + +#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) +#include #include #include -#include +inline QAndroidJniObject qtAndroidContext() +{ + auto result = QtAndroid::androidActivity(); + if ( result.isValid() ) + return result; + return QtAndroid::androidService(); +} + +inline void runOnAndroidMainThread( const QtAndroid::Runnable &runnable ) +{ + QtAndroid::runOnAndroidThread( runnable ); +} + +#else +#include +#include +#include + +inline QJniObject qtAndroidContext() +{ + return QJniObject( QCoreApplication::instance()->nativeInterface()->context() ); +} + +inline void runOnAndroidMainThread( const std::function &runnable ) +{ + QCoreApplication::instance()->nativeInterface()->runOnAndroidMainThread( [runnable]() { + runnable(); + return QVariant(); + } ); +} +#endif #endif namespace sentry_wrapper @@ -63,12 +97,15 @@ namespace sentry_wrapper sentry_value_set_by_key( crumb, "level", sentry_value_new_string( logLevelForMessageType( type ) ) ); - sentry_value_t location = sentry_value_new_object(); - sentry_value_set_by_key( - location, "file", sentry_value_new_string( context.file ) ); - sentry_value_set_by_key( - location, "line", sentry_value_new_int32( context.line ) ); - sentry_value_set_by_key( crumb, "data", location ); + if ( context.file && !QString( context.file ).isEmpty() ) + { + sentry_value_t location = sentry_value_new_object(); + sentry_value_set_by_key( + location, "file", sentry_value_new_string( context.file ) ); + sentry_value_set_by_key( + location, "line", sentry_value_new_int32( context.line ) ); + sentry_value_set_by_key( crumb, "data", location ); + } sentry_add_breadcrumb( crumb ); @@ -123,8 +160,8 @@ namespace sentry_wrapper void init() { #if ANDROID - QtAndroid::runOnAndroidThread( [] { - QAndroidJniObject activity = QtAndroid::androidActivity(); + runOnAndroidMainThread( [] { + auto activity = qtAndroidContext(); if ( activity.isValid() ) { activity.callMethod( "initiateSentry" );