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.
pull/27/head
Fox2Code 3 years ago
parent a082e1fbd4
commit e3a7420bea

@ -1,4 +1,5 @@
plugins { plugins {
// Gradle doesn't allow conditionally enabling/disabling plugins
id "io.sentry.android.gradle" version "3.1.5" id "io.sentry.android.gradle" version "3.1.5"
id 'com.android.application' id 'com.android.application'
id 'com.mikepenz.aboutlibraries.plugin' id 'com.mikepenz.aboutlibraries.plugin'
@ -78,16 +79,18 @@ aboutLibraries {
additionalLicenses = ["LGPL_3_0_only"] 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 { sentry {
// Disable sentry on F-Droid flavor // Disable sentry on F-Droid flavor
ignoredFlavors = ["fdroid"] ignoredFlavors = hasSentryConfig ? [] : ["default", "fdroid"]
// Disables or enables the handling of Proguard mapping for Sentry. // Disables or enables the handling of Proguard mapping for Sentry.
// If enabled the plugin will generate a UUID and will take care of // If enabled the plugin will generate a UUID and will take care of
// uploading the mapping to Sentry. If disabled, all the logic // uploading the mapping to Sentry. If disabled, all the logic
// related to proguard mapping will be excluded. // related to proguard mapping will be excluded.
// Default is enabled. // Default is enabled.
includeProguardMapping = true includeProguardMapping = hasSentryConfig
// Whether the plugin should attempt to auto-upload the mapping file to Sentry or not. // 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. // 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). // 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. // If enabled, the plugin will try to consume and upload the mapping file produced by Dexguard and External Proguard.
// Default is disabled. // Default is disabled.
experimentalGuardsquareSupport = true experimentalGuardsquareSupport = hasSentryConfig
// Disables or enables the automatic configuration of Native Symbols // Disables or enables the automatic configuration of Native Symbols
// for Sentry. This executes sentry-cli automatically so // for Sentry. This executes sentry-cli automatically so
@ -110,20 +113,20 @@ sentry {
// This executes sentry-cli with the --include-sources param. automatically so // This executes sentry-cli with the --include-sources param. automatically so
// you don't need to do it manually. // you don't need to do it manually.
// Default is disabled. // Default is disabled.
includeNativeSources = true includeNativeSources = hasSentryConfig
// Enable or disable the tracing instrumentation. // Enable or disable the tracing instrumentation.
// Does auto instrumentation for specified features through bytecode manipulation. // Does auto instrumentation for specified features through bytecode manipulation.
// Default is enabled. // Default is enabled.
tracingInstrumentation { tracingInstrumentation {
enabled = true enabled = hasSentryConfig
} }
// Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations). // Enable auto-installation of Sentry components (sentry-android SDK and okhttp, timber and fragment integrations).
// Default is enabled. // Default is enabled.
// Only available v3.1.0 and above. // Only available v3.1.0 and above.
autoInstallation { autoInstallation {
enabled = true enabled = hasSentryConfig
// Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations. // Specifies a version of the sentry-android SDK and fragment, timber and okhttp integrations.
// //
@ -140,6 +143,13 @@ sentry {
configurations { configurations {
implementation.exclude group: 'org.jetbrains', module: 'annotations' 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 { dependencies {
@ -169,12 +179,14 @@ dependencies {
implementation 'com.github.Fox2Code:RosettaX:1.0.9' implementation 'com.github.Fox2Code:RosettaX:1.0.9'
implementation 'com.github.Fox2Code:AndroidANSI:1.0.1' implementation 'com.github.Fox2Code:AndroidANSI:1.0.1'
// Error reporting if (hasSentryConfig) {
defaultImplementation 'io.sentry:sentry-android:6.5.0' // Error reporting
defaultImplementation 'io.sentry:sentry-android-fragment:6.5.0' defaultImplementation 'io.sentry:sentry-android:6.5.0'
defaultImplementation 'io.sentry:sentry-android-okhttp:6.5.0' defaultImplementation 'io.sentry:sentry-android-fragment:6.5.0'
defaultImplementation 'io.sentry:sentry-android-core:6.5.0' defaultImplementation 'io.sentry:sentry-android-okhttp:6.5.0'
defaultImplementation 'io.sentry:sentry-android-ndk:6.5.0' defaultImplementation 'io.sentry:sentry-android-core:6.5.0'
defaultImplementation 'io.sentry:sentry-android-ndk:6.5.0'
}
// Markdown // Markdown
implementation "io.noties.markwon:core:4.6.2" implementation "io.noties.markwon:core:4.6.2"
@ -201,4 +213,26 @@ if (hasSentryConfig) {
environment "SENTRY_URL", properties.getProperty("defaults.url") environment "SENTRY_URL", properties.getProperty("defaults.url")
environment "SENTRY_AUTH_TOKEN", properties.getProperty("auth.token") environment "SENTRY_AUTH_TOKEN", properties.getProperty("auth.token")
} }
} }
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
}
}
}

@ -46,10 +46,6 @@ import io.noties.markwon.syntax.Prism4jThemeDefault;
import io.noties.markwon.syntax.SyntaxHighlightPlugin; import io.noties.markwon.syntax.SyntaxHighlightPlugin;
import io.noties.prism4j.Prism4j; import io.noties.prism4j.Prism4j;
import io.noties.prism4j.annotations.PrismBundle; 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( @PrismBundle(
includeAll = true, includeAll = true,

@ -12,6 +12,7 @@ import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.Keep;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.fox2code.androidansi.AnsiConstants; import com.fox2code.androidansi.AnsiConstants;
@ -272,6 +273,7 @@ public class InstallerActivity extends FoxActivity {
} }
@Keep
private void doInstall(File file, boolean noExtensions, boolean rootless) { private void doInstall(File file, boolean noExtensions, boolean rootless) {
if (this.canceled) return; if (this.canceled) return;
UiThreadHandler.runAndWait(() -> { UiThreadHandler.runAndWait(() -> {

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="QueryAllPackagesPermission">
<application android:icon="@mipmap/ic_launcher">
</application>
</manifest>

@ -9,7 +9,7 @@ buildscript {
project.ext.sentryConfigFile = new File(rootDir, "sentry.properties").getAbsoluteFile() project.ext.sentryConfigFile = new File(rootDir, "sentry.properties").getAbsoluteFile()
project.ext.hasSentryConfig = sentryConfigFile.exists() project.ext.hasSentryConfig = sentryConfigFile.exists()
dependencies { 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}" classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${latestAboutLibsRelease}"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

Loading…
Cancel
Save