Loading index.html from assets into WebView but other files referenced in index.html can't be found
09:08 12 Jul 2019

Problem

I am able to successfully load my index.html file in my WebView from the local assets directory with webView.loadUrl("file:///android_asset/www/index.html);

The page remains white and I get js errors in my chrome debug console that say that the *.js and *.css files that are linked in the index.html are not able to be found. Filed to load resource: net:: ERR_FILE_NOT_FOUND.

Information

WebView settings

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);

WebView also has a custom WebChromeClient and WebViewClient.

index.html

    
    
    
      
       ...
       
       ...
    

    
      
      ...
      
      ...
    

    

I have a www directory inside my assets directory that contains my website content.

Directory Structure:

  • assets
    • www
      • index.html
      • *.js (many js files)
      • styles.css
      • etc

All the files are located in the same directory as the index.html so I'm not sure why they aren't able to be found.

Is there something with the Android WebView that is causing this error? I'm at a loss here.

android webview