Open DysaniazzZ opened 4 years ago
1、R.dimen.p_80 是这么引用的:android:minHeight="@dimen/p_80"
,然后比如其他的 R.dimen.p_50 是这么引用的:android:layout_width="@dimen/p_50"
,而且对应的控件也的确是在 UI 中用的到的。
2、support 包里的无关资源应该怎么删掉(这部分虽然和此开源库无关,但是还是想请大神指点一二)。
3、assets 里的资源大概是这么引用的:InputStream ins = context.getAssets().open(module + "/version.json");
是因为不是硬编码写死在代码里所以判定为无用资源吗?
4、同2,如果无效,是否有好的删除方法,因为和 2 一样,是打包时直接就编到 apk 里的,是还要单独拆包去删除吗?
@jqctop1
1、对应的 layout 也用到了,是某个 ListView 的 BaseAdapter 的 getView 方法 inflate 的 item 布局。
@DysaniazzZ 再仔细检查一下代码是否是废弃的?我们之前遇到的类似case都是代码是废弃代码最终proguard删除了
这个 100% 确认的确是用到了,没有被 proguard 删除。我可以给你看下代码公共部分的 proguard 配置:
# For more information, see https://www.guardsquare.com/en/products/proguard/manual/usage
# Input/Output options
# Specifies not to ignore non-public library classes.
-dontskipnonpubliclibraryclasses
# Specifies not to ignore package visible library class members (fields and methods).
-dontskipnonpubliclibraryclassmembers
# Shrinking options
# none
# Optimization options
# Specifies the optimizations to be enabled and disabled.
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
# Specifies the number of optimization passes to be performed.
-optimizationpasses 5
# Obfuscation options
# Specifies to apply aggressive overloading while obfuscating.
-overloadaggressively
# Specifies not to generate mixed-case class names while obfuscating.
-dontusemixedcaseclassnames
# see https://www.guardsquare.com/en/products/proguard/manual/usage/attributes
-keepattributes *Annotation*,InnerClasses,Signature,SourceFile,LineNumberTable
# Preverification options
# Specifies not to preverify the processed class files.
-dontpreverify
# Specifies that the processed class files are targeted at the Android platform.
-android
# General options
# Specifies to write out some more information during processing.
-verbose
# Specifies not to warn about unresolved references and other important problems at all.
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
# Specifies to print any warnings about unresolved references and other important problems, but to continue processing in any case.
-ignorewarnings
# For a complete android application
# see https://www.guardsquare.com/en/products/proguard/manual/examples#android
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
# For native methods
# see https://www.guardsquare.com/en/products/proguard/manual/examples#native
-keepclasseswithmembernames class * {
native <methods>;
}
# For enumeration classes
# see https://www.guardsquare.com/en/products/proguard/manual/examples#enumerations
-keepclassmembers,allowoptimization enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
# To reduce apk size and provide advanced protection
# see https://www.guardsquare.com/en/products/proguard/manual/examples#repacking
# Specifies to repackage all class files that are renamed, by moving them into the single given package.
-repackageclasses †
# Specifies that the access modifiers of classes and class members may be broadened during processing.
-allowaccessmodification
# Understand the @Keep support annotation.
# For android support
-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
# For androidx
-keep class androidx.annotation.Keep
-keep @androidx.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@androidx.annotation.Keep <init>(...);
}
# Optional
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
@DysaniazzZ 可以提供一下你的apk?以及引用到那个layout的class名?
没问题,我上传了。以及代码和资源的 mapping 文件。举一个例子:调用路径是:com.xiaojie.tv.settings.CheckItemsAdapter.getScaleView()
方法里 inflate 了 item_check_box
这个布局,然后这个布局里有一个控件使用了 R.dimen_p_50
。但是 apkchecker 判定 R.dimen_p_50
是没用到的。
Archive.zip
上面的里面漏了一个 R.txt,生成的结果是通过 Matrix-Android-ApkChecker 里介绍的 java -jar ApkChecker.jar --config CONFIG-FILE-PATH
方式生成的。
@DysaniazzZ 你的这个apk资源貌似有问题?资源的名称都是一样的
用ApkTool反编译出来都是这样的,感觉是否resguard使用错误?可以先去掉resguard再用ApkChecker检测无用资源试试看呢?
还是不行,Find out the unused resources
的结果还是不准确,比如 R.layout.view_playbill
这个资源文件是明显在代码里用到,而且也的确是要展示的 UI。但是检查的结果显示这个是无用的。我把没有使用 AndResGuard
,直接用 assembleRelease
生成的 apk 文件以及 mapping.txt/R.txt 等文件和我生成的结果都放在 Archive.zip 里了。
@DysaniazzZ 这个问题找到原因了,是因为你是用的R8,这是使用R8的mapping文件格式:
使用proguard的mapping文件格式是下面这样的:
我尽快兼容下R8的mapping文件格式
@jqctop1 好的,感谢。
@jqctop1 何时兼容R8的mapping文件格式?目前来看【2020-07-09】,还是存在检测不准确问题,确认项目用到了相关资源文件,但被标记为了未使用
@jqctop1 大佬,R8 mapping 文件格式现在支持了吗
还是存在确认使用的文件 被检测出来未使用,还有 两个文件md5一样,但是其实是不同文件
异常类型:无异常,数据错误
手机型号:无
手机系统版本:无
matrix版本:0.6.0
gradle版本:3.5.0
问题描述:如题,在使用 Apk Checker 的时候有些 task 产生的结果并不准确。 1、Find out the unused resources 下的
R.dimen.p_80
和R.color.white_50
这种都是我代码或者 xml 文件里用到的,但是 task 显示这是无用的; 2、Find out the unused resources 出现了好多 android support 包下的资源,这部分可以在代码中去掉吗?如何去掉,以及有没有副作用? 3、Find out the unused assets 下的那几个文件代码里也都是使用了的,但是检查显示没有用到。 4、Find out the duplicated files 下列出了好多 META-INF/androidx.xxx 的重复文件,这部分应该被判定为重复文件吗,因为我只是按照规定引用了 androidx 的支持库。堆栈/日志(这里是制定 apk checker 后产生的结果文件):