Prevent Proguard from deleting specific drawings

In my Android project, I have some images stored in res / drawable / which are only available from the HTML file uploaded to Webview. For example (HTML code):

<img src="file:///android_res/drawable/myfriend.png"> 

These images are removed by Proguard from apk during optimization.

Does anyone know a way to save these files (even if they are not used directly in Java code)?

+13
optimization android drawable proguard
Jun 08 2018-11-11T00:
source share
2 answers

I moved the images to the "assets" folder, which solved my problem:

 <img src="file:///android_asset/myfriend.png"> 
+1
Jun 11 2018-11-11T00:
source share

I had a similar problem and wanted to add only a few bits.

Resources are NOT deleted by ProGuard. If you just unzip your apk, you will see that image files still exist.

The problem is that Webkit FileLoader will try to load your R $ drawable class using reflection. If you do not add the keep rule to the proguard.cfg file, this class will be renamed, so Webkit will not be able to load your resource.

By placing the file in the resource folder, you bypass the class R system and everything will work.

This is not a solution, though, for example, if you want to use different resources for different densities.

I suggest you just add a very basic keep rule to preserve R inner classes and fields:

 -keepclassmembers class **.R$* { public static <fields>; } -keep class **.R$* 
+22
Jan 19 '12 at 12:01
source share



All Articles