Missing classes detected while running R8报错解决方案

Android 打包release版本时报错如下:

bash 复制代码
> Task :printlib:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/mac/Documents/code/PrintDemo/printlib/build/outputs/mapping/release/missing_rules.txt.","sources":[{}]}
AGPBI: {"kind":"error","text":"Missing class com.hw.hwbaselib.adapter.BaseRvAdapter (referenced from: void com.hw.printlib.adapter.BluetoothDeviceAdapter.<init>() and 1 other context)","sources":[{}],"tool":"R8"}

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/mac/Documents/code/PrintDemo/printlib/build/outputs/mapping/release/missing_rules.txt.

Missing class com.hw.hwbaselib.adapter.BaseRvAdapter (referenced from: void com.hw.printlib.adapter.BluetoothDeviceAdapter.<init>() and 1 other context)

解决方案:

查看AGP依赖的版本,项目中依赖的AGP版本如下:

bash 复制代码
[versions]
agp = "8.5.1"

这个版本太高了,容易出现混淆打包的问题,修改成如下版本就可以解决问题了

bash 复制代码
[versions]
agp = "8.3.2"

如果改完了还是报错,如下:

bash 复制代码
> Task :app:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/mac/Documents/code/PrintDemo/app/build/outputs/mapping/release/missing_rules.txt.","sources":[{}]}
AGPBI: {"kind":"error","text":"Missing class javax.annotation.Nullable (referenced from: okio.Segment okio.Buffer.head and 2 other contexts)","sources":[{}],"tool":"R8"}

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/mac/Documents/code/PrintDemo/app/build/outputs/mapping/release/missing_rules.txt.

Missing class javax.annotation.Nullable (referenced from: okio.Segment okio.Buffer.head and 2 other contexts)

需要把上述报错中的这句话中的txt文件中的内容,复制到当前module的混淆配置文件中,

Missing classes detected while running R8. Please add the missing

classes or apply additional keep rules that are generated in

/Users/mac/Documents/code/PrintDemo/app/build/outputs/mapping/release/missing_rules.txt

在电脑中找到这个文件,打开,如下:

我的这个missing_rules.txt文件中,内容是这样的,每个项目可能不一样,直接复制里面内容,放到混淆文件中就可以了

复制代码
# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn javax.annotation.Nullable

最后打包就成功了

相关推荐
代码s贝多芬的音符5 小时前
ios android 小程序 蓝牙 CRC16_MODBUS
android·ios·小程序
2501_915918417 小时前
iOS 混淆实战 多工具组合完成 IPA 混淆、加固与工程化落地(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·ios·小程序·https·uni-app·iphone·webview
雨白7 小时前
让协程更健壮:全面的异常处理策略
android·kotlin
Jeled8 小时前
AI: 生成Android自我学习路线规划与实战
android·学习·面试·kotlin
游戏开发爱好者89 小时前
如何系统化掌握 iOS 26 App 耗电管理,多工具协作
android·macos·ios·小程序·uni-app·cocoa·iphone
shaominjin1239 小时前
android在sd卡中可以mkdir, 但是不可以createNewFile
android·开发语言·python
AI科技星10 小时前
垂直原理:宇宙的沉默法则与万物运动的终极源头
android·服务器·数据结构·数据库·人工智能
用户416596736935511 小时前
Kotlin Coroutine Flow 深度解析:剖析 `flowOn` 与上下文切换的奥秘
android
2501_9159214311 小时前
运营日志驱动,在 iOS 26 上掌握 App 日志管理实践
android·macos·ios·小程序·uni-app·cocoa·iphone
沐怡旸11 小时前
【Android】详细讲解ViewDragHelper的实现原理(不含代码版)
android