From e3a7420bea4bada27df40b292c8dbc946fa0034f Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Tue, 18 Oct 2022 16:00:10 +0200 Subject: [PATCH] Use `sentry.properties` existence over build flavor to set sentry enabled state. (Fix #214) This will also disable sentry by default on community builds/forks. --- app/build.gradle | 60 +++++++++++++++---- .../com/fox2code/mmm/MainApplication.java | 4 -- .../mmm/installer/InstallerActivity.java | 2 + .../{default => sentry}/AndroidManifest.xml | 0 .../fox2code/mmm/sentry/SentryBreadcrumb.java | 0 .../com/fox2code/mmm/sentry/SentryMain.java | 0 app/src/sentryless/AndroidManifest.xml | 9 +++ .../fox2code/mmm/sentry/SentryBreadcrumb.java | 0 .../com/fox2code/mmm/sentry/SentryMain.java | 0 build.gradle | 2 +- 10 files changed, 59 insertions(+), 18 deletions(-) rename app/src/{default => sentry}/AndroidManifest.xml (100%) rename app/src/{default => sentry}/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java (100%) rename app/src/{default => sentry}/java/com/fox2code/mmm/sentry/SentryMain.java (100%) create mode 100644 app/src/sentryless/AndroidManifest.xml rename app/src/{fdroid => sentryless}/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java (100%) rename app/src/{fdroid => sentryless}/java/com/fox2code/mmm/sentry/SentryMain.java (100%) diff --git a/app/build.gradle b/app/build.gradle index a0bf388..98dc757 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ plugins { + // Gradle doesn't allow conditionally enabling/disabling plugins id "io.sentry.android.gradle" version "3.1.5" id 'com.android.application' id 'com.mikepenz.aboutlibraries.plugin' @@ -78,16 +79,18 @@ aboutLibraries { additionalLicenses = ["LGPL_3_0_only"] } +// "true" is not allowed inside this block, use "hasSentryConfig" instead. +// This is because gradle doesn't allow to enable/disable plugins conditionally sentry { // Disable sentry on F-Droid flavor - ignoredFlavors = ["fdroid"] + ignoredFlavors = hasSentryConfig ? [] : ["default", "fdroid"] // Disables or enables the handling of Proguard mapping for Sentry. // If enabled the plugin will generate a UUID and will take care of // uploading the mapping to Sentry. If disabled, all the logic // related to proguard mapping will be excluded. // Default is enabled. - includeProguardMapping = true + includeProguardMapping = hasSentryConfig // Whether the plugin should attempt to auto-upload the mapping file to Sentry or not. // If disabled the plugin will run a dry-run and just generate a UUID. @@ -98,7 +101,7 @@ sentry { // Experimental flag to turn on support for GuardSquare's tools integration (Dexguard and External Proguard). // If enabled, the plugin will try to consume and upload the mapping file produced by Dexguard and External Proguard. // Default is disabled. - experimentalGuardsquareSupport = true + experimentalGuardsquareSupport = hasSentryConfig // Disables or enables the automatic configuration of Native Symbols // for Sentry. This executes sentry-cli automatically so @@ -110,20 +113,20 @@ sentry { // This executes sentry-cli with the --include-sources param. automatically so // you don't need to do it manually. // Default is disabled. - includeNativeSources = true + includeNativeSources = hasSentryConfig // Enable or disable the tracing instrumentation. // Does auto instrumentation for specified features through bytecode manipulation. // Default is enabled. tracingInstrumentation { - enabled = true + enabled = hasSentryConfig } // Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations). // Default is enabled. // Only available v3.1.0 and above. autoInstallation { - enabled = true + enabled = hasSentryConfig // Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations. // @@ -140,6 +143,13 @@ sentry { configurations { implementation.exclude group: 'org.jetbrains', module: 'annotations' + if (!hasSentryConfig) { + implementation.exclude group: 'io.sentry', module: 'sentry-android' + implementation.exclude group: 'io.sentry', module: 'sentry-android-fragment' + implementation.exclude group: 'io.sentry', module: 'sentry-android-okhttp' + implementation.exclude group: 'io.sentry', module: 'sentry-android-core' + implementation.exclude group: 'io.sentry', module: 'sentry-android-ndk' + } } dependencies { @@ -169,12 +179,14 @@ dependencies { implementation 'com.github.Fox2Code:RosettaX:1.0.9' implementation 'com.github.Fox2Code:AndroidANSI:1.0.1' - // Error reporting - defaultImplementation 'io.sentry:sentry-android:6.5.0' - defaultImplementation 'io.sentry:sentry-android-fragment:6.5.0' - defaultImplementation 'io.sentry:sentry-android-okhttp:6.5.0' - defaultImplementation 'io.sentry:sentry-android-core:6.5.0' - defaultImplementation 'io.sentry:sentry-android-ndk:6.5.0' + if (hasSentryConfig) { + // Error reporting + defaultImplementation 'io.sentry:sentry-android:6.5.0' + defaultImplementation 'io.sentry:sentry-android-fragment:6.5.0' + defaultImplementation 'io.sentry:sentry-android-okhttp:6.5.0' + defaultImplementation 'io.sentry:sentry-android-core:6.5.0' + defaultImplementation 'io.sentry:sentry-android-ndk:6.5.0' + } // Markdown implementation "io.noties.markwon:core:4.6.2" @@ -201,4 +213,26 @@ if (hasSentryConfig) { environment "SENTRY_URL", properties.getProperty("defaults.url") environment "SENTRY_AUTH_TOKEN", properties.getProperty("auth.token") } -} \ No newline at end of file +} + +final String sentrySrc = hasSentryConfig ? 'src/sentry/java' : 'src/sentryless/java' +final String sentryManifestSrc = hasSentryConfig ? + 'src/sentry/AndroidManifest.xml' : 'src/sentryless/AndroidManifest.xml' + +android { + sourceSets { + main { + java.srcDirs += sentrySrc + // manifest.srcFile += sentryManifestSrc // Not supported + } + + // Workaround useless gradle restriction + "default" { + manifest.srcFile sentryManifestSrc + } + + fdroid { + manifest.srcFile sentryManifestSrc + } + } +} diff --git a/app/src/main/java/com/fox2code/mmm/MainApplication.java b/app/src/main/java/com/fox2code/mmm/MainApplication.java index b01e477..ff805d6 100644 --- a/app/src/main/java/com/fox2code/mmm/MainApplication.java +++ b/app/src/main/java/com/fox2code/mmm/MainApplication.java @@ -46,10 +46,6 @@ import io.noties.markwon.syntax.Prism4jThemeDefault; import io.noties.markwon.syntax.SyntaxHighlightPlugin; import io.noties.prism4j.Prism4j; import io.noties.prism4j.annotations.PrismBundle; -import io.sentry.JsonObjectWriter; -import io.sentry.NoOpLogger; -import io.sentry.android.core.SentryAndroid; -import io.sentry.android.fragment.FragmentLifecycleIntegration; @PrismBundle( includeAll = true, diff --git a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java index cff88e1..b2ea81b 100644 --- a/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java +++ b/app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java @@ -12,6 +12,7 @@ import android.view.View; import android.view.WindowManager; import android.widget.Toast; +import androidx.annotation.Keep; import androidx.recyclerview.widget.RecyclerView; import com.fox2code.androidansi.AnsiConstants; @@ -272,6 +273,7 @@ public class InstallerActivity extends FoxActivity { } + @Keep private void doInstall(File file, boolean noExtensions, boolean rootless) { if (this.canceled) return; UiThreadHandler.runAndWait(() -> { diff --git a/app/src/default/AndroidManifest.xml b/app/src/sentry/AndroidManifest.xml similarity index 100% rename from app/src/default/AndroidManifest.xml rename to app/src/sentry/AndroidManifest.xml diff --git a/app/src/default/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java b/app/src/sentry/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java similarity index 100% rename from app/src/default/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java rename to app/src/sentry/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java diff --git a/app/src/default/java/com/fox2code/mmm/sentry/SentryMain.java b/app/src/sentry/java/com/fox2code/mmm/sentry/SentryMain.java similarity index 100% rename from app/src/default/java/com/fox2code/mmm/sentry/SentryMain.java rename to app/src/sentry/java/com/fox2code/mmm/sentry/SentryMain.java diff --git a/app/src/sentryless/AndroidManifest.xml b/app/src/sentryless/AndroidManifest.xml new file mode 100644 index 0000000..56958dc --- /dev/null +++ b/app/src/sentryless/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/fdroid/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java b/app/src/sentryless/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java similarity index 100% rename from app/src/fdroid/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java rename to app/src/sentryless/java/com/fox2code/mmm/sentry/SentryBreadcrumb.java diff --git a/app/src/fdroid/java/com/fox2code/mmm/sentry/SentryMain.java b/app/src/sentryless/java/com/fox2code/mmm/sentry/SentryMain.java similarity index 100% rename from app/src/fdroid/java/com/fox2code/mmm/sentry/SentryMain.java rename to app/src/sentryless/java/com/fox2code/mmm/sentry/SentryMain.java diff --git a/build.gradle b/build.gradle index be694be..ed357b8 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { project.ext.sentryConfigFile = new File(rootDir, "sentry.properties").getAbsoluteFile() project.ext.hasSentryConfig = sentryConfigFile.exists() dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' + classpath 'com.android.tools.build:gradle:7.3.1' classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}" // NOTE: Do not place your application dependencies here; they belong