Android: Can't find .html file in res / raw after obfuscation

I have some html files in res/raw

which I open in WebView

. But after obfuscation, they cannot load.


source to share

4 answers

I faced this same problem. I have a help html file in raw and after obfuscation. I run my application and I get an error that the file was not found.

Here is my HelpActivity class:

public class HelpActivity extends BaseActivity
  protected void onCreate(Bundle savedInstanceState)
      // requesting to turn the title OFF
      // making it full screen
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

      WebView webView = (WebView) findViewById(;
      webView.loadUrl("file:///android_" + getString(R.raw.how_to_play_zeewee));


I fixed this problem by adding the following to my proguard.cfg file:

-keepclassmembers class **.R$* {public static <fields>;}
-keep class **.R$*


You probably already have the first line, but that doesn't get in the way of this issue. Adding the second line completely fixed the problem. I don't think the first line is still needed, but I haven't tested it yet, and since it currently works ...;).



Suggested in answer to this question -

-keep class **.R$*


is not the most elegant solution as it instructs ProGuard to keep all classes R

regardless of which package they are in.

Having the same problem with WebView

, the error I see in my Logcat:

... E / AndroidProtocolHandler: Unable to open resource URL: file: ///android_res/raw/$MISSING_RESOURCE_NAME.css java.lang.ClassNotFoundException: class " $ raw" could not be found in path: DexPathList [ [...

The maximum restriction instruction I added to my file


-keepnames class$raw { public static <fields>; }


Obviously, since the class R

only contains fields and all those fields are of type public static

, in practice there shouldn't be any difference between the above and

-keepnames class$raw { *; } 


However, here I am

  1. DO NOT disable compression and obfuscation for all other inner classes in R

    except raw

  2. targeting R

    in one specific package only.

    This approach should be better in case you have more than one module in your project that provides its own resources that may not be needed for one specific APK you are building (having, say, more than one android_application module - APK sources - in your project).

To understand the difference between -keepnames

and -keep

, refer to the following.

Distinguishing Between Various ProGuard Directives -keep

- Tuesday May 29th 04:10:50 AM MSK 2018



add the following to proguard.cfg and see if it doesn't matter

-keep public class com.yourPackageName.yourAppName.R
-keepclassmembers class **.R$ { public static ; }




See the first answer here:

Prevent Proguard from deleting certain blueprints

This worked for me.



All Articles