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

最后打包就成功了

相关推荐
朝星1 天前
Android开发[2]:Flow
android·kotlin
zzb15801 天前
Android Activity 与 Intent 学习笔记
android·笔记·学习
studyForMokey1 天前
【Android面试】动画 & Bitmap
android·面试·职场和发展
黑牛儿1 天前
面试高频问题:从浏览器请求到PHP响应:完整流程拆解
android·后端·面试·php
y小花1 天前
安卓USB服务概述
android·usb
alexhilton1 天前
Compose中初始加载逻辑究竟应该放在哪里?
android·kotlin·android jetpack
zh_xuan1 天前
启动RN服务端口被占用
android·react native
Code-keys1 天前
Android Codec2 Filter 算法模块开发指南
android·算法·音视频·视频编解码
y = xⁿ1 天前
MySQL:count(1)与count(*)有什么区别,深分页问题
android·数据库·mysql
程序员陆业聪2 天前
Android启动全景图:一次冷启动背后到底发生了什么
android