shrinkResources 在build.gradle
.
然后我发现了这个奇怪的错误:
在我的应用程序的 java 文件中,有这样一行:
String unit = String.format("%%s %s", getResources().getString(R.string.XXXX));
注意里面有个空格%%s %s
如果我添加这个空间,我的一些 PNG 将被 ShrinkResources 标记为未使用的资源,并且不会被打包到 apk 文件中。
但如果我省略空格,一切都很好。
对我来说,这太不可思议了。这会让我发疯……你知道吗?
更新:
试图让我的问题更清楚:
如果我的 java 代码是
String unit = String.format("%%s %s", getResources().getString(R.string.XXXX));
然后部分输出是(实际上我在 中找到它resources.txt
):
Skipped unused resource res/drawable-xxhdpi-v4/head02.9.png: 822 bytes (replaced with small dummy file of size 77 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/appointment_normal.png: 1827 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/cg_normal.png: 1850 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/pre_normal.png: 1822 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/doctor_normal.png: 1963 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/infor_normal.png: 1605 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/btn_check.png: 716 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/btn_check.png: 898 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/navigation_arrow_left_normal.png: 184 bytes (replaced with small dummy file of size 67 bytes)
Skipped unused resource res/drawable-xxhdpi-v4/dameon_killed.png: 913 bytes (replaced with small dummy file of size 67 bytes)
跳过的 png 将不会显示。
如果我的 java 代码是
String unit = String.format("%%s%s", getResources().getString(R.string.XXXX));
没有像我上面发布的输出,一切都很好。