Android 12 中与 CoreComponentFactory 和前提条件相关的异常或发布版本中的以下内容

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

我仅在 Android 12 及更低版本中收到以下异常,如果它处于发布状态(调试正常工作) - 当应用程序打开时,异常发生在运行时:

Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/~~iaVUd900SBAkCvdX52zU5w==/com.quare.blitzsplit-b_5H-WForkfoIt1bmmzx_A==/base.apk"],nativeLibraryDirectories=[/data/app/~~iaVUd900SBAkCvdX52zU5w==/com.quare.blitzsplit-b_5H-WForkfoIt1bmmzx_A==/lib/arm64, /data/app/~~iaVUd900SBAkCvdX52zU5w==/com.quare.blitzsplit-b_5H-WForkfoIt1bmmzx_A==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.LoadedApk.createAppFactory(LoadedApk.java:262)
    at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:975)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:1062)
    at android.app.LoadedApk.getResources(LoadedApk.java:1310)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:3037)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:3029)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6660)
    at android.app.ActivityThread.access$1500(ActivityThread.java:256)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
    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:7870)
    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:1003)
 FATAL EXCEPTION: main
Process: com.quare.blitzsplit, PID: 19725
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/Preconditions;
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7459)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6976)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6747)
    at android.app.ActivityThread.access$1500(ActivityThread.java:256)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091)
    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:7870)
    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:1003)
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.common.internal.Preconditions
    at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source:2) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:7459) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6976) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6747) 
    at android.app.ActivityThread.access$1500(ActivityThread.java:256) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2091) 
    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:7870) 
    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:1003) 

这是我的

libs.versions.toml
文件:

[versions]
datastore = "1.1.2"
hilt = "2.51.1"
materialNavigation = "1.7.6"
retrofit = "2.9.0"
compose-bom = "2025.01.00"
activity-compose = "1.10.0"
firebase-bom = "33.8.0"
android-gradle-plugin = "8.8.0"
kotlin = "2.1.0"
google-services = "4.4.2"
credentials-play-service-auth = "1.5.0-rc01"
goolge-id = "1.1.1"
navigation-compose = "2.8.5"
hilt-navigation-compose = "1.2.0"
constraintLayoutCompose = "1.1.0"
coil = "2.6.0"
kotlinSerializationJson = "1.6.3"
gson = "2.10.1"
okHttp = "4.12.0"
firebase-crashlytics = "3.0.2"
kotlinxCoroutinesCore = "1.8.0"
permissions = "0.34.0"
inAppUpdateVersion = "2.1.0"
assertK = "0.26.1"
junit5 = "5.10.2"
mockk = "1.13.10"
junit5Plugin = "1.9.3.0"

[libraries]
androidXCredentials = { module = "androidx.credentials:credentials", version.ref = "credentials-play-service-auth" }
androidXCredentialsPlayServicesAuth = {module = "androidx.credentials:credentials-play-services-auth", version.ref = "credentials-play-service-auth" }
googleId = { module = "com.google.android.libraries.identity.googleid:googleid", version.ref = "goolge-id" }

# Compose
composeBom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
material-navigation = { module = "androidx.compose.material:material-navigation", version.ref = "materialNavigation" }
ui = { group = "androidx.compose.ui", name = "ui" }
uiGraphics = { group = "androidx.compose.ui", name = "ui-graphics" }
uiTooling = { group = "androidx.compose.ui", name = "ui-tooling" }
uiToolingPreview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
uiTestManifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
material3 = { group = "androidx.compose.material3", name = "material3" }
icons = { group = "androidx.compose.material", name = "material-icons-extended" }
activityCompose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
navigationCompose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigation-compose" }
constraintLayoutCompose = { group = "androidx.constraintlayout", name = "constraintlayout-compose", version.ref = "constraintLayoutCompose" }

#Gson
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }

# Coil
coil = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }

# Lifecycle
viewModelKtx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx" }
lifecycleRuntimeCompose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose" }

# Hilt
daggerHilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
daggerHiltCompiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt" }
hilt-core = { module = "com.google.dagger:hilt-core", version.ref = "hilt" }
hiltNavigationCompose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hilt-navigation-compose" }

# Firebase
firebaseBom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebase-bom" }
firebaseAnalytics = { group = "com.google.firebase", name = "firebase-analytics" }
firebaseCrashlytics = { group = "com.google.firebase", name = "firebase-crashlytics" }
firebase-auth-ktx = { group = "com.google.firebase", name = "firebase-auth-ktx" }

# Retrofit
retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
retrofitConverterGson = { group = "com.squareup.retrofit2", name = "converter-gson", version.ref = "retrofit" }
okHttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okHttp" }

# Accompanist
accompanistPermissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "permissions" }

# In-App Update
inAppUpdate = { group = "com.google.android.play", name = "app-update", version.ref = "inAppUpdateVersion" }
inAppUpdateKtx = { group = "com.google.android.play", name = "app-update-ktx", version.ref = "inAppUpdateVersion" }

# Other
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" }
datastorePreferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastore" }
kotlinSerialization = { group = "org.jetbrains.kotlin", name = "kotlin-serialization", version.ref = "kotlin" }
kotlinSerializationJson = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinSerializationJson" }
googleServices = { group = "com.google.gms", name = "google-services", version.ref = "google-services" }

# Testing
assertK = { group = "com.willowtreeapps.assertk", name = "assertk", version.ref = "assertK" }
junit5Api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit5" }
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
junit5Engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit5" }

[plugins]
androidLibrary = { id = "com.android.library", version.ref = "android-gradle-plugin" }
androidApplication = { id = "com.android.application", version.ref = "android-gradle-plugin" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
hiltAndroid = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
googleServices = { id = "com.google.gms.google-services", version.ref = "google-services" }
firebaseCrashLytics = { id = "com.google.firebase.crashlytics", version.ref = "firebase-crashlytics" }
junit5 = { id = "de.mannodermaus.android-junit5", version.ref = "junit5Plugin" }

我的项目中有很多模块,所以我只在这里放置 :app 模块,如果需要,我会添加更多 gradle 模块:

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.kotlinAndroid)
    alias(libs.plugins.googleServices)
    alias(libs.plugins.hiltAndroid)
    alias(libs.plugins.composeCompiler)
    alias(libs.plugins.firebaseCrashLytics)
    kotlin("kapt")
}

android {
    namespace = "com.quare.blitzsplit"
    compileSdk = project.property("compileSdkVersion").toString().toInt()

    defaultConfig {
        applicationId = "com.quare.blitzsplit"
        minSdk = project.property("minSdkVersion").toString().toInt()
        targetSdk = project.property("targetSdkVersion").toString().toInt()
        versionCode = project.property("versionCode").toString().toInt()
        versionName = project.property("versionName").toString()
        ndk {
            debugSymbolLevel = "FULL"
        }
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            signingConfig = signingConfigs.getByName("debug")
        }
    }
    kotlinOptions {
        jvmTarget = project.property("jvmTarget").toString()
    }
    buildFeatures {
        compose = true
        buildConfig = true
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_21
        targetCompatibility = JavaVersion.VERSION_21
    }
}

dependencies {
    implementFeature(
        Module.Feature.Home.Data,
        Module.Feature.Home.Domain,
        Module.Feature.Home.Presentation,
        Module.Feature.Contacts.Data,
        Module.Feature.Contacts.Domain,
        Module.Feature.AddContactToGroup,
        Module.Feature.Group.Data,
        Module.Feature.Group.Domain,
        Module.Feature.Group.Presentation,
        Module.Feature.Groups.Data,
        Module.Feature.Groups.Domain,
        Module.Feature.Groups.Presentation,
        Module.Feature.Debts.Data,
        Module.Feature.Debts.ByUser.Data,
        Module.Feature.Debts.ByUser.Domain,
        Module.Feature.Debts.ByUser.Presentation,
        Module.Feature.Debts.ByGroup.Data,
        Module.Feature.Debts.ByGroup.Domain,
        Module.Feature.Debts.ByGroup.Presentation,
        Module.Feature.Main.Data,
        Module.Feature.Main.Domain,
        Module.Feature.Main.Presentation,
        Module.Feature.Expense.Data,
        Module.Feature.Expense.Domain,
        Module.Feature.Expense.Presentation,
        Module.Feature.CreateGroup.Data,
        Module.Feature.CreateGroup.Domain,
        Module.Feature.CreateGroup.Presentation,
        Module.Feature.JoinGroup.Data,
        Module.Feature.JoinGroup.Domain,
        Module.Feature.JoinGroup.Presentation,
        Module.Feature.Split,
        Module.Feature.SplitDialog,
    )
    implementCore(
        Module.Core.Activity,
        Module.Core.Analytics,
        Module.Core.User,
        Module.Core.Navigation,
        Module.Core.Provider.City,
        Module.Core.Provider.Language,
        Module.Core.Provider.Image,
    )
    implementUi(
        Module.Ui.Theme,
        Module.Ui.Component.Category,
        Module.Ui.Utils,
    )

    // Compose
    implementation(platform(libs.composeBom))
    implementation(libs.ui)
    implementation(libs.uiGraphics)
    implementation(libs.uiToolingPreview)
    implementation(libs.material3)
    implementation(libs.navigationCompose)
    debugImplementation(libs.uiTooling)
    debugImplementation(libs.uiTestManifest)

    // Hilt
    implementation(libs.daggerHilt)
    kapt(libs.daggerHiltCompiler)

    // Retrofit
    implementation(libs.retrofit)
    implementation(libs.retrofitConverterGson)

    // Firebase
    implementation(platform(libs.firebaseBom))
    implementation(libs.firebaseCrashlytics)

    // In App Update
    implementation(libs.inAppUpdate)
    implementation(libs.inAppUpdateKtx)
}

// Allow references to generated code
kapt {
    correctErrorTypes = true
}

hilt {
    enableAggregatingTask = true
}

这是我的

proguard-rules.pro
文件:

# Retrofit 2.x
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

# Gson
-keep class com.google.gson.stream.** { *; }

# Keep fields with @SerializedName annotation
-keepclassmembers class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

# Preserve annotations and class members
-keep class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

# Preserve CredentialManager and its dependencies
-if class androidx.credentials.CredentialManager
-keep class androidx.credentials.playservices.** {
  *;
}

我解决了这个问题,在我的 gradle 中更改了它,对于发布版本:

            isMinifyEnabled = false

但我不想禁用这个标志。如何在不禁用的情况下解决?

android firebase gradle
1个回答
0
投票

我在

proguard-rules.pro
文件中添加了以下内容来解决问题:

# Firebase
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**
-keepattributes Signature, InnerClasses, *Annotation*

# Google Play Services
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.google.android.gms.common.internal.** { *; }
-keep class com.google.android.gms.tasks.** { *; }
© www.soinside.com 2019 - 2024. All rights reserved.