在多模块项目中集成 Crashlytics

Integrating Crashlytics in a multi-module project

我有一个 Android 项目,其中包含一个主模块和多个其他子模块。我通过更新项目级别 build.gradle 和主模块 build.gradle:

成功地将 Crashlytics 集成到项目中

项目级gradle:

buildscript {
    repositories {
        jcenter()
        maven {url 'https://maven.google.com'}
        maven {url 'https://maven.fabric.io/public'}
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'io.fabric.tools:gradle:1.31.2'
    }
}

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

主模块build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

android {
    ...
}

dependencies {
    implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1') {
        transitive = true;
    }

    ...

    implementation project(':modules:sensordata:collection:ambient:module-wifinetwork')
    ...
}

repositories {
    maven { url 'https://dl.bintray.com/rvalerio/maven' }
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    google()
    jcenter()
}

build.gradle 对于模块 module-wifinetwork(每个模块都相似):

apply plugin: 'com.android.library'

android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        debug {
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        targetCompatibility = 1.8
        sourceCompatibility = 1.8
    }

}

dependencies {
    implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1') {
        transitive = true;
    }
    ...
}

我的问题是来自主模块的崩溃报告被正确发送到 firebase 后端,而其他模块中的崩溃报告没有,即使它们被正确识别,因为如果我把这个命令放在 class 在子模块中:

Crashlytics.getInstance().crash();

我收到以下信息:

2019-12-18 10:19:54.328 29944-30002/it.unitn.disi.witmee.sensorlog E/EventBus: Could not dispatch event: class it.unitn.disi.witmee.modules.core.systembus.model.BusObject to subscribing class class it.unitn.disi.witmee.modules.core.systembus.core.SensorlogMainBus
    java.lang.ArrayIndexOutOfBoundsException: length=2; index=10
        at com.crashlytics.android.core.CrashTest.indexOutOfBounds(CrashTest.java:30)
        at com.crashlytics.android.core.CrashlyticsCore.crash(CrashlyticsCore.java:635)
        at com.crashlytics.android.Crashlytics.crash(Crashlytics.java:340)
        at it.unitn.disi.witmee.modules.sensordatacollection.ambient.wifinetwork.runnables.SensorRunnable.run(SensorRunnable.java:38)
        at it.unitn.disi.witmee.modules.sensordatacollection.sensormodule.receivers.StartAllBroadcastReceiver.busEventCallback(StartAllBroadcastReceiver.java:23)
        at it.unitn.disi.witmee.modules.core.systembus.core.SensorlogMainBus.onEvent(SensorlogMainBus.java:219)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:507)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:501)
        at org.greenrobot.eventbus.BackgroundPoster.run(BackgroundPoster.java:64)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)

知道为什么这在子模块中不起作用吗?谢谢

我发现了问题,只需要重建项目。所以解决方案是将以下元素添加到项目级别 build.gradle 和主模块 build.gradle,不要添加到单个模块 build.gradle。然后清理并重建您的项目。

项目级 build.gradle:

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

    dependencies {
        ...
        classpath 'io.fabric.tools:gradle:1.31.2'
    }
}

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

主模块build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'

android {
    ...
}

dependencies {
    implementation ('com.crashlytics.sdk.android:crashlytics:2.10.1') {
        transitive = true;
    }

    ...


repositories {
    ...
}