Skip to content

[BUG] Android 使用 R8 minify 时报告 fastjson1 相关 class 缺失导致编译失败 #2466

@layou233

Description

@layou233

问题描述

Android 使用 R8 minify 时报告 fastjson1 相关 class 缺失导致编译失败。观察源码发现似乎存在几处兼容 fastjson1 的逻辑(见日志),可能引发了该问题。使用前几个版本时没有遇到过这些问题,不清楚是否 fastjson2 或者 gradle/android 插件更新引发的新错误。

环境信息

"com.alibaba.fastjson2:fastjson2:2.0.49.android5"

"com.android.application" version 8.3.1

源码 https://github.com/layou233/MCPingForAndroid

重现步骤

在 build.gradle 中启用 minifyEnabled 然后使用 Gradle assembleRelease task 进行编译即可触发。没有自行添加任何 proguard rule。

相关日志输出

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in <MyProjectDirectory>/app/build/outputs/mapping/release/missing_rules.txt.

Missing class com.alibaba.fastjson.JSONArray (referenced from: java.lang.Class com.alibaba.fastjson2.JSONFactory.getClassJSONArray1x())
Missing class com.alibaba.fastjson.JSONObject (referenced from: java.lang.Object com.alibaba.fastjson2.JSONFactory$FJ1ObjectInnerSupplier.apply(java.lang.Object) and 3 other contexts)

附加信息

目前我的临时解决方案是添加一行 ProGuard 规则:

# Ignore fastjson v1 references to make minifier happy.
-dontwarn com.alibaba.fastjson.*

因为我的项目没有依赖 fastjson1 ,我直接忽略掉了 fastjson1 相关警告,可以正常编译,并且在实机上简单测试发现应用运行正常。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions