Amazon设备出现IncompatibleClassChangeError:DrawScope崩溃求助
Crashlytics收到崩溃事件,集中出现在Amazon设备上,崩溃详情如下:
Fatal Exception: java.lang.IncompatibleClassChangeError
Found interface androidx.compose.ui.graphics.drawscope.DrawScope, but class was expected (declaration of 'androidx.compose.ui.graphics.drawscope.DrawScope' appears in /data/app/dI2D-_x33YVzjrNGowkPgw==/com.m128kb.~~~-WnvHnaVmpCa58IEaXGiQAw==/base.apk)
已尝试使用最新Android Studio、切换多个JDK版本,问题仍未解决,寻求帮助。
项目build.gradle配置
buildscript { dependencies { classpath 'com.google.gms:google-services:4.3.14' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' classpath 'com.google.firebase:perf-plugin:1.4.2' } repositories { google() mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } }// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '7.3.1' apply false id 'com.android.library' version '7.3.1' apply false id 'org.jetbrains.kotlin.android' version '1.7.20' apply false } task clean(type: Delete) { delete rootProject.buildDir }
应用build.gradle配置
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'kotlin-parcelize' id 'com.google.gms.google-services' id 'com.google.firebase.crashlytics' id 'com.google.firebase.firebase-perf' } android { compileSdk 33 defaultConfig { applicationId "com.m128kb." minSdk 24 targetSdk 33 versionCode 19 versionName "4.0.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary true } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility "1.8" targetCompatibility "1.8" } kotlinOptions { freeCompilerArgs = ['-Xjvm-default=all-compatibility'] jvmTarget = "1.8" } buildFeatures { compose true } composeOptions { kotlinCompilerExtensionVersion = "1.3.2" } packagingOptions { resources { excludes += '/META-INF/{AL2.0,LGPL2.1}' } } namespace 'com.m128kb.' } dependencies { def composeBom = platform('androidx.compose:compose-bom:2022.12.00') implementation composeBom androidTestImplementation composeBom implementation 'androidx.compose.material:material' implementation 'androidx.compose.ui:ui' //LiveData implementation 'androidx.compose.runtime:runtime-livedata' // Android Studio Preview support implementation 'androidx.compose.ui:ui-tooling-preview' debugImplementation 'androidx.compose.ui:ui-tooling' //Icon implementation 'androidx.compose.material:material-icons-extended' //Fonts implementation 'androidx.compose.ui:ui-text-google-fonts' implementation 'androidx.core:core-ktx:1.9.0' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' implementation 'androidx.activity:activity-compose:1.6.1' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.7.0' implementation 'com.google.android.gms:play-services-ads:21.4.0' // UI Tests androidTestImplementation 'androidx.compose.ui:ui-test-junit4' debugImplementation 'androidx.compose.ui:ui-test-manifest' //Testing testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' //Coroutine implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4' //Coil implementation "io.coil-kt:coil-compose:2.2.2" def nav_version = "2.5.3" implementation "androidx.navigation:navigation-compose:$nav_version" implementation 'com.google.accompanist:accompanist-navigation-animation:0.28.0' //Firebase implementation platform('com.google.firebase:firebase-bom:31.1.1') implementation 'com.google.firebase:firebase-firestore-ktx' implementation 'com.google.firebase:firebase-storage-ktx' implementation 'com.google.firebase:firebase-crashlytics-ktx' implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-messaging-ktx' implementation 'com.google.firebase:firebase-inappmessaging-display-ktx' implementation 'com.google.firebase:firebase-perf-ktx' implementation("com.google.accompanist:accompanist-systemuicontroller:0.28.0") def lifecycle_version = "2.2.0" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version" annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" //ViewModel implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1") implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1") //Retrofit implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' // define a BOM and its version implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0")) // define any required OkHttp artifacts without version implementation("com.squareup.okhttp3:okhttp") implementation("com.squareup.okhttp3:logging-interceptor") //lottie def lottieVersion = "5.2.0" implementation "com.airbnb.android:lottie-compose:$lottieVersion" }
这个错误源于Compose依赖版本不兼容:DrawScope在新版Compose中是接口,但旧版实现为类,依赖冲突会触发该异常。针对你的配置,按以下步骤修复:
升级Compose与Kotlin版本
- 项目级build.gradle中,将Kotlin版本改为
1.8.20:plugins { id 'org.jetbrains.kotlin.android' version '1.8.20' apply false } - 应用级build.gradle中,更新Compose BOM和编译器版本:
def composeBom = platform('androidx.compose:compose-bom:2023.08.00') composeOptions { kotlinCompilerExtensionVersion = "1.4.8" }
- 项目级build.gradle中,将Kotlin版本改为
清理重复的Lifecycle依赖
删除旧版lifecycle-extensions和lifecycle-runtime依赖,统一使用2.5.1版本:// 移除以下行 def lifecycle_version = "2.2.0" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"强制统一Compose依赖版本
在应用级build.gradle的dependencies块末尾添加配置,避免依赖冲突:configurations.all { resolutionStrategy { force 'androidx.compose.ui:ui:1.5.3' force 'androidx.compose.material:material:1.5.3' force 'androidx.compose.runtime:runtime-livedata:1.5.3' } }清理构建缓存并重建
- 执行命令:
./gradlew clean - 重启Android Studio后重新构建项目
- 执行命令:
Amazon设备适配检查
部分Amazon Fire OS版本可能自带过时组件,确保测试覆盖主流Fire OS版本,确认minSdk 24的兼容性。
内容的提问来源于stack exchange,提问作者Marwan Talal

