android Not allowed to load local resource:file:///android_asset

I’m trying to load an html page from a server the page contains a script that links to android sdcard .js file.


  • Android Studio AVD error launching
  • set mouse position on rooted android device
  • Cannot start Emulator in android studio 2.0
  • What's the best way to uniquely identify Android users to a server?
  • Android listView find the amount of pixels scrolled
  • how i can break things with Fragments with setRetainInstance(true) and adding them to backstack?
  • String url ="";


    <script src="file:///sdcard/test.js"></script>

    I’ve also tried :

    <script src="file:///android_asset/www/js/test.js"></script>

    test.js file exists and js file path is correct.
    But in logcat:

    03-18 13:01:12.467: E/Web Console(26189): Not allowed to load local
    resource: file:///sdcard/test.js at :0


    03-18 13:01:53.467: E/Web Console(26189): Not allowed to load local
    resource: file:///android_asset/www/js/test.js at :0

  • Create borders on a android view in drawable xml, on 3 sides?
  • How can I get the options menu of my Activity?
  • Android: Is it possible to display video thumbnails?
  • Emulator's Location simulation not working
  • How to achieve a full-screen dialog as described in material guidelines?
  • how to keep RecyclerView always scroll bottom
  • 4 Solutions collect form web for “android Not allowed to load local resource:file:///android_asset”

    This may help

    webview.loadDataWithBaseURL( "file:///android_asset/", html, "text/html", 
    "utf-8", null ); 

    If you getting “Not allowed to load local resource: file:///android_asset/index.html” error most probably your problem is putting assets folder in wrong location.

    For gradle project store your assets folder under src/main/ directory by the java and res folders. Like this:


    For maven project store yout assets under res/ directory

    to fix this create a folder in “main” called “android_asset” and inside android_asset folder create another folder called “assets” and place your html file in assets and call using this mWebView.loadUrl(“file:///android_asset/YOUR HTML FILE.html”);

    I had the same problem and even though I dont call mWebView.loadUrl(“file:///android_asset/assets/YOUR HTML FILE.html”); it still some how works. which i find strange because thats where the html actually is!

    So again your folders should look like this main/android_assets/assets/YOUR HTML.html and call with mWebView.loadUrl(“file:///android_asset/YOUR HTML FILE.html”);

    Heres how my oncreate looks.

    public class MainActivity extends ActionBarActivity {

    private WebView mWebView;
    protected void onCreate(Bundle savedInstanceState) {
        mWebView = (WebView) findViewById(;
        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();

    try this :


    but there should be one folder name www->js in your assets folder.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.