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

Re-adding sentry to builds #4298

Merged
merged 4 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions platform/android/build.gradle.in
Original file line number Diff line number Diff line change
Expand Up @@ -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'
m-kuhn marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 6 additions & 2 deletions src/sentry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
55 changes: 46 additions & 9 deletions src/sentry/sentry_classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,44 @@

#include <sentry.h>
#ifdef ANDROID
#include <android/log.h>

#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
#include <QAndroidJniEnvironment>
#include <QAndroidJniObject>
#include <QtAndroid>

#include <android/log.h>
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 <QJniEnvironment>
#include <QJniObject>
#include <QtCore/private/qandroidextras_p.h>

inline QJniObject qtAndroidContext()
{
return QJniObject( QCoreApplication::instance()->nativeInterface<QNativeInterface::QAndroidApplication>()->context() );
}

inline void runOnAndroidMainThread( const std::function<void()> &runnable )
{
QCoreApplication::instance()->nativeInterface<QNativeInterface::QAndroidApplication>()->runOnAndroidMainThread( [runnable]() {
runnable();
return QVariant();
} );
}
#endif
#endif

namespace sentry_wrapper
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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<void>( "initiateSentry" );
Expand Down
Loading