在 Android Studio 项目中将 `sentry.properties` 文件放在哪里?

Where to put `sentry.properties` file in Android Studio project?

文档对我帮助不大。 我尝试过的地点:

我在扩展 android.app.Application 的 class 中启动我的应用程序时初始化 Sentry,如下所示:

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

然后用我的方法之一进行测试捕获:

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

我还尝试在 gradle.properties 中明确指定 sentry.properties 文件的路径,但没有成功。

当我使用接受 DSN 的 Sentry.init() 方法时,它可以工作,但这不是我想要的,因为我不想将 DSN 签入 VCS。

我知道其他配置方法,但我只想使用 sentry.properties

按照官方文档中给出的设置 System Environment Variable 进行尝试:

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.

实际上有两个个不同的sentry.properties个文件。

  1. 应用在运行时用来配置DSN的sentry.properties应该放在/app/src/main/resourcesdocumentation)。

  2. Gradle 在构建时使用的 sentry.properties 生成 ProGuard 映射并将其上传到 Sentry。这应该放在项目根目录中。 (documentation)。这是可选的,仅与使用 ProGuard 的应用相关。

我发现 sentry.properties 文件应放在应用程序的根目录中。

  • 例如,如果我在 XYZ 文件夹中设置我的项目,然后将 sentry.properties 放在同一个文件夹中(它是您找到 AppName.iml、gradle.properties 等的同一目录)

the documentation 中声明 app/src/main/resources/ 是 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/