React Native Android报错:找不到com.facebook.drawee.ImagePerfDataListener类
异常信息
致命异常:mqt_native_modules
原因:java.lang.ClassNotFoundException:在路径DexPathList[[zip文件"/data/app/~~QD95sJ0ANNQuaa8RuGZCOw==/com.roots.rootsapp-yLZJ1_fvihTZ4to330UwBA==/base.apk"],nativeLibraryDirectories=[/data/app/~~QD95sJ0ANNQuaa8RuGZCOw==/com.roots.rootsapp-yLZJ1_fvihTZ4to330UwBA==/lib/x86_64, /data/app/~~QD95sJ0ANNQuaa8RuGZCOw==/com.roots.rootsapp-yLZJ1_fvihTZ4to330UwBA==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]]上未找到类"com.facebook.drawee.backends.pipeline.info.ImagePerfDataListener"
这个异常是由于运行时无法找到Fresco库中的ImagePerfDataListener类,通常由依赖缺失、版本不兼容或构建配置问题导致,以下是针对性解决方案:
检查Fresco依赖配置
确保Module级别的build.gradle中正确引入了Fresco核心及相关模块依赖,React Native项目需额外确认react-native与fresco的依赖关联:// 原生Android项目示例 implementation 'com.facebook.fresco:fresco:2.6.0' implementation 'com.facebook.fresco:imagepipeline:2.6.0' // React Native项目示例(适配RN 0.70+) implementation 'com.facebook.react:react-native:0.71.x' implementation 'com.facebook.fresco:fresco:2.6.0' implementation 'com.facebook.fresco:imagepipeline-okhttp3:2.6.0'注意替换为与项目匹配的版本号。
清理重建项目
执行以下命令清除缓存并重新构建:# Android项目 ./gradlew clean && ./gradlew assembleDebug # React Native项目 npx react-native clean && npx react-native run-android也可通过IDE的Clean Project/Rebuild Project功能操作。
配置Dex分包(若方法数超限)
若项目方法数超过65536,需开启MultiDex:android { defaultConfig { multiDexEnabled true } } dependencies { implementation 'androidx.multidex:multidex:2.0.1' }自定义Application类需继承
MultiDexApplication,或在attachBaseContext中添加MultiDex.install(this)。修复ProGuard/R8混淆规则
若开启了代码混淆,需在proguard-rules.pro中添加Fresco的保留规则,避免类被误删:-keep class com.facebook.drawee.** { *; } -keep class com.facebook.imagepipeline.** { *; }验证依赖版本兼容性
React Native项目需确保react-native版本与fresco版本兼容,例如RN 0.70+建议使用Fresco 2.6.0及以上版本,避免版本不匹配导致的类缺失。
内容的提问来源于stack exchange,提问作者Akshay I

