You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多模块Kotlin Android项目集成Crashlytics后无崩溃日志问题

Android项目Crashlytics集成后无崩溃日志问题排查

问题描述

我有一个包含主模块和多个子模块的Android项目,已更新项目级和主模块的build.gradle完成Crashlytics集成,但Firebase控制台始终无法显示崩溃日志。使用相同包名的Demo项目测试,Crashlytics可以正常工作。

相关配置代码

1. 项目级build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = '1.8.0'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url "https://maven.google.com" // Google's Maven repository}
        }
        maven {  url "https://zendesk.jfrog.io/zendesk/repo" }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath 'com.google.gms:google-services:4.3.13'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
        classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
        classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1'
    }
    configurations.all {
        resolutionStrategy {
            // Override the default version of ProGuard
            // with the most recent one.
            force 'net.sf.proguard:proguard-gradle:6.2.0'
        }
    }

}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
        maven {  url "https://zendesk.jfrog.io/zendesk/repo" }
         flatDir {
            dirs 'libs','aar'
        }
    }


}

task clean(type: Delete) {
    delete rootProject.buildDir
}
subprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << '-Xmaxerrs' << '500'
        }
    }
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "26.1.0"
            }
        }
    }
}

2. 主模块build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'jacoco'

buildscript {
    ext.kotlin_version = '1.8.0'

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

android {
    signingConfigs {
    }
    compileSdk 34
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'

    }
    defaultConfig {
        configurations.all {
            resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
        }
        applicationId "com.abc.testapp"
        minSdkVersion 24
        targetSdkVersion 34
        versionCode 277
        versionName "3.77"
        testApplicationId "com.abc.testapp.test"
        testInstrumentationRunner "com.abc.testapp.Instrumentation"
        multiDexEnabled true
        signingConfig signingConfigs.Shellnet
    }

    buildTypes {
        release {
            debuggable false
            minifyEnabled false
            shrinkResources false
            firebaseCrashlytics {
                nativeSymbolUploadEnabled true
                strippedNativeLibsDir "libs"
                unstrippedNativeLibsDir "libs"
            }
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
            proguardFile 'proguard-rules.pro'
            buildConfigField "String", "TEST_TAGS", "\"${getTestTags()}\""
        }
        debug {
            debuggable true
            minifyEnabled false
            shrinkResources false
            firebaseCrashlytics {
                nativeSymbolUploadEnabled true
                strippedNativeLibsDir "libs"
                unstrippedNativeLibsDir "libs"
            }
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
            proguardFile 'proguard-rules.pro'
            buildConfigField "String", "TEST_TAGS", "\"${getTestTags()}\""

        }
    }

    dataBinding {
        enabled = true
    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }
    sourceSets {
        androidTest {
            assets.srcDirs = ['src/androidTest/assets']
        }
    }

    productFlavors {
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.3.0'
    testImplementation 'junit:junit:4.13.2'
    implementation 'com.google.android.material:material:1.4.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    implementation 'androidx.test.uiautomator:uiautomator:2.2.0'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.4.0'
    implementation project(':sub')

    androidTestImplementation 'org.mockito:mockito-core:4.5.1'
    androidTestImplementation 'com.google.dexmaker:dexmaker:1.2'
    androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2'
    androidTestImplementation('androidx.test.espresso:espresso-contrib:3.4.0') {
        exclude module: 'support-annotations'
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }

    implementation 'com.google.android.gms:play-services-gcm:17.0.0'
    implementation 'com.google.android.gms:play-services-analytics:18.0.1'
    implementation 'com.google.firebase:firebase-messaging:21.0.1'
    implementation 'com.google.firebase:firebase-core:21.0.0'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.firebase:digitsmigrationhelpers:0.1.1'
    implementation 'com.firebaseui:firebase-ui-auth:7.2.0'
    implementation 'com.google.firebase:firebase-crash:16.2.1'
    implementation 'androidx.multidex:multidex:2.0.1'


    implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '5.0.0-alpha.2'
    implementation group: 'com.squareup.okio', name: 'okio', version: '3.0.0-alpha.6'

    // Branch required
    implementation 'io.branch.sdk.android:library:5.2.6'
    implementation 'com.android.installreferrer:installreferrer:2.2'
    implementation 'com.google.firebase:firebase-appindexing:19.0.0'
    implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0'
    // Chrome Tab matching (enables 100% guaranteed matching based on cookies)
    implementation 'androidx.browser:browser:1.0.0'

    // Unit testing using cucumber
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.annotation:annotation:1.3.0'
    androidTestImplementation 'info.cukes:cucumber-android:1.2.6'
    androidTestImplementation 'info.cukes:cucumber-picocontainer:1.2.6'
    testImplementation 'info.cukes:cucumber-junit:1.2.6'

    // Facebook SDK
    implementation 'com.facebook.android:facebook-android-sdk:11.0.0'
    implementation 'com.facebook.android:facebook-applinks:11.0.0'

    // Add the Firebase Crashlytics and Analytics SDK.
    implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.12'
    implementation 'com.google.firebase:firebase-analytics-ktx:21.1.0'

    /*Issue from google play store
    com.google.android.gms:play-services-safetynet:17.0.0*/
    implementation('com.google.firebase:firebase-auth') {
        exclude module: "play-services-safetynet"
    }
}

def getTestTags() {
    return project.hasProperty("tags") ? project.getProperties().get("tags") : ""
}

排查修复建议

  • 移除旧版Crash依赖:主模块依赖中同时存在com.google.firebase:firebase-crash:16.2.1(旧版Fabric Crash)和新版Crashlytics,二者会冲突,直接删除旧版依赖。
  • 统一Kotlin插件版本:项目级build.gradle中同时声明了Kotlin插件1.8.0和1.6.21,保留一个(建议用1.8.0),避免版本冲突导致的异常。
  • 验证google-services.json:确保项目根目录的google-services.json与Demo项目完全一致,包名、项目ID等信息必须匹配。
  • 检查Crashlytics启用状态:确认代码中没有调用FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(false)禁用上报;手动触发测试崩溃(比如throw new RuntimeException("Test Crash"))后,重启应用等待上报完成。
  • 清理构建缓存:执行./gradlew clean后重新构建项目,避免缓存导致的配置不生效问题。
  • 确认网络权限:确保应用清单中声明了INTERNET权限,崩溃日志需要联网才能上报到Firebase控制台。

内容的提问来源于stack exchange,提问作者jaigish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 09:35:53