在多模块项目中集成Crashlytics

问题描述 投票:-1回答:1

我有一个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()
}

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

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后端,而其他模块中的崩溃报告却没有被发送,因为如果我将此命令放在子目录的类中,模块:

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)

任何线索为什么在子模块中不起作用?谢谢

android crashlytics google-fabric crashlytics-android
1个回答
0
投票

我发现了问题,只需要重建项目。因此,解决方案是将以下元素添加到项目级别的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 {
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.