'Android WebView may not find raw files in release mode

I have some html files to display on phone screen. I put them in raw folders and use this code :

private WebView _mWebView;

_mWebView=(WebView)findViewById(R.id.webView1);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // N Nougat 24
    _mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
            return false; //  the link is done by webView
        }
    });
}
String webUrl="file:///android_res/raw/objective.html";
_mWebView.loadUrl(webUrl);
....

In some case the program displays the html files, but in other cases it displays an error message.

Executing in debug mode, html pages are displayed.

Generating a release Apk with minifyEnabled false, executing, html pages are displayed.

Generating a release Apk with minifyEnabled true, directly or from AppBundle, executing give "Web page not available Url web page at file:///android-res/raw/objective.html could not be loaded because net: ERR_FILE_NOT_FOUND"

Problem occurs on Android studio emulator (updated to last version), I have done same tests on a Samsung phone and I have not the error, so I don't know if there is problem only with emulator, or if it may be problem with other kinds of phone.

I have moved files to assets folder and loaded by android-asset, there is no more problem, but in contrary of raw files which are localized resources, assets fils are not localized.

So I have no solution to generate compact Apk from AppBundle :

  • leaving minifyEnabled to false increase size of about 1 megabytes,
  • using assets files, there will be a set of html files by translation.

Probably minifyEnabled has deleted classes used to access raw files in WebView processing, but how identify these classes ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source