【发布时间】:2023-03-11 19:45:01
【问题描述】:
我正在将 MobileFirst 7 库用于本机 Android 应用程序,但发现它严重增加了我的 Android 应用程序的 dex 方法计数(将其推过65,536 limit)。
根据Adding the IBM MobileFirst Platform Foundation SDK to a new or existing application with Android Studio 的文章,我在build.gradle 中添加了以下内容:
compile group: 'com.ibm.mobile.foundation',
name: 'ibmmobilefirstplatformfoundation',
version: '7.1.0.0',
ext: 'aar',
transitive: true
根据methodscount.com,MobileFirst 库(及其依赖项)引入了多达 39,364 个方法(占可用 dex 方法计数的 60%)!
我认为 Proguard 可能有助于减少使用 MobileFirst 的影响,但发现示例 proguard-project.txt 具有以下指令:
-keep class com.google.** { *;}
据我了解,这有效地告诉 Proguard 不要删除任何 Google Guava 方法。 MobileFirst 还引入了其他库,但我从 Guava 开始,因为它是最大的。
然后我决定调查 MobileFirst 使用 Guava 库的情况:
$ unzip ibmmobilefirstplatformfoundation-7.1.0.aar
$ jadx --output-dir temp/ classes.jar
$ grep -roh . -e 'com.google.common.*' | sort | uniq
哪个发现对任何 Guava 库的引用为零(允许反编译器可能缺少某些引用),但似乎可以排除 Guava 依赖项?
compile(group: 'com.ibm.mobile.foundation',
name: 'ibmmobilefirstplatformfoundation',
version: '7.1.0.0',
ext: 'aar',
transitive: true) {
exclude group: 'com.google.guava', module: 'guava'
}
如果不是这样(排除番石榴会是个问题),那么:
- 是否有更好的 Proguard 规则可用于仅保留 MobileFirst 依赖项中必需的方法?
- 是否也可以排除 MobileFirst 依赖的其他大型库?
【问题讨论】:
标签: android ibm-mobilefirst proguard