11

The documentation was not very helpful for me. Locations I've tried:

  • root folder (where gradle.properties and project's build.gradle files reside)
  • /app folder (where app's build.gradle file is localed)
  • /app/src/main/kotlin

I initialize Sentry on start of my app in class that extends android.app.Application like so:

    class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Sentry.init(AndroidSentryClientFactory(applicationContext))
    }
}

And then do a test capture in one of my methods:

Sentry.capture("This is a test capture using Sentry")

I also tried to specify the path to sentry.properties file explicitly in gradle.properties with no luck.

When I use Sentry.init() method that accepts DSN, it works, but this is not desired, because I do not want to check DSN into VCS.

I am aware of other methods of configuration, I just want to use sentry.properties though.

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
Sevastyan Savanyuk
  • 5,797
  • 4
  • 22
  • 34

4 Answers4

8

There are in fact two different sentry.properties files.

  1. The sentry.properties that is used by the app at runtime to configure the DSN should be placed at /app/src/main/resources (documentation).

  2. The sentry.properties that is used at build time by Gradle to generate and upload ProGuard mappings to Sentry. This should be placed in the project root. (documentation). This is optional and only relevant for apps that use ProGuard.

James
  • 3,597
  • 2
  • 39
  • 38
  • it is wrong way, check this post https://stackoverflow.com/a/59070456/4797289 – Rasoul Miri Nov 27 '19 at 12:42
  • 1
    @RasoulMiri - the answer was correct, but there are now two different sentry.properties files for different purposes. I have updated the answer accordingly. – James Nov 27 '19 at 22:34
2

I found out that sentry.properties file should be placed in the root directory of the app.

  • For example if I have setup my project in XYZ folder then put sentry.properties in the same folder (its a same directory where you find AppName.iml, gradle.properties etc etc)
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Moulesh
  • 2,762
  • 1
  • 22
  • 32
0

Try it by setting System Environment Variable as given here in official documentation:

https://docs.sentry.io/clients/java/config/#configuration-via-properties-file

The Java SDK can be configured via a .properties file that is located on the filesystem or on your application’s classpath. By default the SDK will look for a sentry.properties file in the current directory or in the root of your classpath. You can override the location of the properties file by using either the sentry.properties.file Java System Property or the SENTRY_PROPERTIES_FILE System Environment Variable.

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • As I mentioned in my post, I know about alternatives, I am just wondering why Sentry cannot find my `sentry.properties` file in the locations, it said it will look for. – Sevastyan Savanyuk Mar 26 '18 at 06:59
0

In the documentation it's stated that app/src/main/resources/ is the default location of sentry.properties for Android.

By default the SDK will look for a sentry.properties file in the application’s current working directory or in the root of your classpath. (...) on Android the default is app/src/main/resources/

jurrdb
  • 301
  • 3
  • 13