Android NoClassDefFoundError: 'android.graphics.BlendMode' - Solution and Compatibility
This error occurs when the Android device or emulator running the app does not support the 'BlendMode' class introduced in Android API level 29 (Android 10). The app is trying to use this class, but the device does not have it, resulting in a 'NoClassDefFoundError'.
To fix this error, you can either:
-
Update the minimum SDK version of your app to 29 (or higher) to ensure that only devices running Android 10 or later can install and run the app.
-
Use a compatibility library such as 'androidx.core.graphics.BlendModeCompat' to provide support for 'BlendMode' on older Android versions.
To use the compatibility library, add the following dependency to your app's build.gradle file:
implementation 'androidx.core:core-ktx:1.3.2'
Then, replace any references to 'android.graphics.BlendMode' with 'androidx.core.graphics.BlendModeCompat'. For example:
// Before
canvas.drawColor(Color.RED, BlendMode.SRC_OVER);
// After
canvas.drawColor(Color.RED, BlendModeCompat.SRC_OVER);
原文地址: https://www.cveoy.top/t/topic/kTVj 著作权归作者所有。请勿转载和采集!