Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Use sentry.properties existence over build flavor to set sentry ena…
Browse files Browse the repository at this point in the history
…bled state. (Fix #214)

This will also disable sentry by default on community builds/forks.
  • Loading branch information
Fox2Code committed Oct 18, 2022
1 parent a082e1f commit e3a7420
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 18 deletions.
60 changes: 47 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
//
Expand All @@ -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 {
Expand Down Expand Up @@ -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"
Expand All @@ -201,4 +213,26 @@ if (hasSentryConfig) {
environment "SENTRY_URL", properties.getProperty("defaults.url")
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
}
}
}
4 changes: 0 additions & 4 deletions app/src/main/java/com/fox2code/mmm/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.Keep;
import androidx.recyclerview.widget.RecyclerView;

import com.fox2code.androidansi.AnsiConstants;
Expand Down Expand Up @@ -272,6 +273,7 @@ protected void onCreate(Bundle savedInstanceState) {
}


@Keep
private void doInstall(File file, boolean noExtensions, boolean rootless) {
if (this.canceled) return;
UiThreadHandler.runAndWait(() -> {
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions app/src/sentryless/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3a7420

Please sign in to comment.