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

最后打包就成功了

相关推荐
工程师老罗2 小时前
如何在Android工程中配置NDK版本
android
Libraeking5 小时前
破壁行动:在旧项目中丝滑嵌入 Compose(混合开发实战)
android·经验分享·android jetpack
市场部需要一个软件开发岗位6 小时前
JAVA开发常见安全问题:Cookie 中明文存储用户名、密码
android·java·安全
JMchen1237 小时前
Android后台服务与网络保活:WorkManager的实战应用
android·java·网络·kotlin·php·android-studio
crmscs8 小时前
剪映永久解锁版/电脑版永久会员VIP/安卓SVIP手机永久版下载
android·智能手机·电脑
localbob8 小时前
杀戮尖塔 v6 MOD整合版(Slay the Spire)安卓+PC端免安装中文版分享 卡牌肉鸽神作!杀戮尖塔中文版,电脑和手机都能玩!杀戮尖塔.exe 杀戮尖塔.apk
android·杀戮尖塔apk·杀戮尖塔exe·游戏分享
机建狂魔8 小时前
手机秒变电影机:Blackmagic Camera + LUT滤镜包的专业级视频解决方案
android·拍照·摄影·lut滤镜·拍摄·摄像·录像
hudawei9968 小时前
flutter和Android动画的对比
android·flutter·动画
lxysbly10 小时前
md模拟器安卓版带金手指2026
android
儿歌八万首11 小时前
硬核春节:用 Compose 打造“赛博鞭炮”
android·kotlin·compose·春节