简体   繁体   English

Kotlin 多平台+哨兵

[英]Kotlin Multiplatform + Sentry

I want to use Sentry for my Multiplatform Kotlin project.我想将 Sentry 用于我的多平台 Kotlin 项目。

Sentry for Kotlin Multiplatform哨兵 Kotlin 多平台

So I was trying to prepare the setup of Sentry with Kotlin Multiplatform.所以我试图用 Kotlin Multiplatform 准备 Sentry 的设置。 I was following the guide, made a mavenLocal() build etc. Now I wanted to add it to the project.我正在按照指南进行操作,进行了 mavenLocal() 构建等。现在我想将它添加到项目中。 However, when starting my (Android) project, even before starting the onCreate() of the Application I get a crash stating:但是,在启动我的 (Android) 项目时,甚至在启动应用程序的 onCreate() 之前,我都会收到崩溃说明:

Unable to get provider io.sentry.android.core.SentryInitProvider: 
java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.

So to be clear this happens already when adding api("io.sentry:sentry-kotlin-multiplatform:0.0.1") to the dependencies.所以需要明确的是,在将api("io.sentry:sentry-kotlin-multiplatform:0.0.1")添加到依赖项时,这种情况已经发生。 Long before the init call.早在 init 调用之前。

All I did was:我所做的只是:

  1. Configure shared build.gradle.kts and add配置共享build.gradle.kts并添加
 val commonMain by getting {
            dependencies {
                api("io.sentry:sentry-kotlin-multiplatform:0.0.1")
  1. Adding the sample configuration添加示例配置
fun initializeSentry(context: Context) {
    Sentry.init(context) { sentryOptions ->  setDsnHere... } 
}

and in the Android Application:并在 Android 申请中:

initializeSentry(this)

Then tried to run it.然后尝试运行它。 But I don't even get to the init call.但我什至没有进入 init 调用。 The configuration should be reached and the initializeSentry(this) block executed.应该达到配置并执行initializeSentry(this)块。 (I can accept if it fails there but I don't even get that far.) (如果它在那里失败我可以接受但我什至没有那么远。)

Instead the app fails stating相反,该应用程序无法说明

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: xyz, PID: 23056
    java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
        at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
        ...

even before anything else.甚至在其他任何事情之前。 So the mere adding to the gradle file causes the crash already (even if the other code is commented out).所以仅仅添加到 gradle 文件就已经导致崩溃(即使其他代码被注释掉)。

-------- Full Stack trace------- -------- 全栈跟踪--------

java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
        at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744)
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

     Caused by: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
        at io.sentry.Sentry.initConfigurations(Sentry.java:201)
        at io.sentry.Sentry.init(Sentry.java:170)
        at io.sentry.Sentry.init(Sentry.java:118)
        at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:87)
        at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:56)
        at io.sentry.android.core.SentryInitProvider.onCreate(SentryInitProvider.java:27)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
        at io.sentry.android.core.SentryInitProvider.attachInfo(SentryInitProvider.java:44)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7462)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744) 
        at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7872) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 

Turns out the manual had forgotten to mention the auto configuration.原来手册忘了提到自动配置。

Add this line to your Manifest:将此行添加到您的清单中:

<meta-data android:name="io.sentry.auto-init" android:value="false" />

and proceed with the tutorial.并继续教程。

For Reference:以供参考:

https://github.com/getsentry/sentry-kotlin-multiplatform/issues/45 https://github.com/getsentry/sentry-kotlin-multiplatform/issues/45

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM