环境
会发生什么:
我有一个组件,它使用facebook.com
创建一种图像按钮。
如果我将应用程序捆绑为 debugRelease ,它的工作原理就像一个超级按钮,并且会显示每个按钮的所有图片。 如果我将应用程序捆绑为 releaseBundle ,则会丢失7张图片中的4张(所有图片均相同)。
我尝试过的事情
因此,按钮1不起作用,按钮2-4不起作用,按钮5-7甚至不起作用。 为确保图像文件没有损坏,我用新名称复制了Button 2的图像,并用这个名称替换了Image 1。 图像仍未显示!
因此,我启动了Android Studio,并在debug-APK和release-APS中打开了apk以检查其中的文件。 结果如下:
您有什么线索,为什么只有一些图像文件没有以正确的方式捆绑到Release-APK中(即使例如文件<ImageBackground>
是有效的{{1 }}这样的文件)?
这是我实现它的方式:
spenden.jpg
答案 0 :(得分:0)
我发现问题的原因是shrinkResources true
中的build.gradle
。
ProGuard无法识别我需要那些文件。
要检查删除了哪些资源,如果您启用了shrinkResources true
,请检查您的<build-directory>/build/outputs/mapping/release/resources.txt
。
就我而言,其中的条目如下:
Skipped unused resource res/drawable/consultation.jpg: 55893 bytes (replaced with small dummy file of size 0 bytes)
Skipped unused resource res/drawable/angebote.jpg: 71099 bytes (replaced with small dummy file of size 0 bytes)
Skipped unused resource res/drawable/nebenwirkungen.jpg: 57250 bytes (replaced with small dummy file of size 0 bytes)
Skipped unused resource res/drawable/redbox_top_border_background.xml: -1 bytes (replaced with small dummy file of size 104 bytes)
Skipped unused resource res/drawable/signet_sachsen.gif: 1925 bytes (replaced with small dummy file of size 0 bytes)
Skipped unused resource res/drawable/spenden.jpg: 68376 bytes (replaced with small dummy file of size 0 bytes)
如何修复
创建一个名为keep.xml
的文件,并将其放在目录/android/app/src/main/res/raw
中。 (如果目录raw
不存在,请创建它。
将其放入文件中:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/spenden,@drawable/angebote" />
重要:不要这样写文件类型: @ drawable / spenden.jpg 。这将无法正常工作。但是,您可以对以下文件名使用通配符: @ drawable / img _ ,这是一种通过一个命令保留所有图像的解决方法。
信息来源: