简体   繁体   English

将Crashlytics集成到库项目中

[英]Integrating Crashlytics to library project

I have a library project (a custom view library project) which doesn't have any Activities/services. 我有一个没有任何活动/服务的图书馆项目(自定义视图库项目)。 I want to integrate Crashlytics SDK to my library. 我想将Crashlytics SDK集成到我的库中。 When I try to add it via Crashlytics plugin (the icon in toolbar) for Android Studio, it just stays on "Checking" for "Select a kit to install" . 当我尝试通过Android Studio的Crashlytics插件(工具栏中的图标)添加它时,它只是"Checking" "Select a kit to install" The question is how can I add Crashlytics to my Android library project? 问题是如何将Crashlytics添加到我的Android库项目中?

Best Regards 最好的祝福

You need an app module at the moment, even if your intention is to integrate Crashlytics only in your library. 您现在需要一个应用程序模块,即使您的目的是仅将Crashlytics集成到您的库中。 If what you only have is the library, there is no reasonable way of doing that, not officially yet at least. 如果您只拥有图书馆,那么没有合理的方法可以做到这一点,至少在官方上是这样。

See below for generating the necessary stuff first in the app side and then moving (some of them) towards your library such as the initialization. 请参阅下面的内容,首先在应用程序端生成必要​​的内容,然后将其(其中一些)移动到库中,例如初始化。

When you onboard a kit, Fabric sets up the initialization code inside the base project, not the library. 当您使用工具包时,Fabric会在基础项目内设置初始化代码,而不是库。 Here's how you'd do it... 这是你怎么做的......

Create an android library project with the following gradle: 使用以下gradle创建一个android库项目:

apply plugin: 'com.android.library'
<-- other project specific includes -->

buildscript {
  repositories {
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
  }
}

apply plugin: 'io.fabric'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
  compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
    transitive = true;
  }
}

To your base project add the maven line to allProjects/repositories: 对于您的基础项目,将maven行添加到allProjects / repositories:

allprojects {
  repositories {
      jcenter()
      mavenCentral()
      maven { url 'https://maven.fabric.io/public' }
  }
}

From your application project add a dependency to the newly created library project. 从您的应用程序项目中添加依赖项到新创建的库项目。 for example: 例如:

compile project(':crashlytics_lib')

It can be done, with the help of the parent app that consumes the module. 可以在使用该模块的父应用程序的帮助下完成。

  • Set up Firebase on the parent using the normal steps. 使用常规步骤在父级上设置Firebase。
  • Add this to the build.gradle of the library module. 将其添加到库模块的build.gradle中。
  implementation 'com.google.firebase:firebase-core:16.0.1'
  implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
  • Create a class in the library module with this static variable. 使用此静态变量在库模块中创建一个类。 public static Crashlytics crash;
  • In the parents Application class, assign Crashlytics.getInstance(); 在父类Application类中,分配Crashlytics.getInstance(); to that variable. 到那个变量。
  • The library module can call crash.core.logException(e); 库模块可以调用crash.core.logException(e); anywhere in the library and sent off to the Firebase console - but include a null check in case eg. 在库中的任何位置并发送到Firebase控制台 - 但包括空检查,例如。 library test methods are being called without a parent app. 在没有父应用程序的情况下调用库测试方法。
  • Other unhandled exceptions eg throw new RuntimeException("test"); 其他未处理的异常,例如throw new RuntimeException("test"); in the library should also show up in the console. 在库中也应该出现在控制台中。

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

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