Developing on Android Studio 1.0.1, API 21. Following is the folder structure -
It's essentially an AngularJS based app that I want to wrap inside a webview container and run on Android.
My Android side of code is -
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient());
String filePath = "file:///android_asset/www/index.html";
myWebView.loadUrl(filePath);
The references in html are all relative -
<script src="lib/jquery.min.js"></script>
<script src="lib/angular.min.js"></script>
<script src="lib/angular-route.min.js"></script>
<script src="lib/bootstrap.min.js"></script>
But interestingly enough, I've searched most places, and I'm not sure where am I going wrong. My references aren't working at all! So I can't access my lib files, my scripts, my css. Also, if I run an external angular web page inside the webview, with the same Java code, it runs perfectly!
Any help is appreciated.
Note : Please don't suggest using Cordova/PhoneGap. It's a project requirement to go native(and I frankly don't understand why, but I'm only a developer who has no say in it).
On a side note : I'm facing the same problem with the iOS webview. References aren't working!
UPDATE
Tried the following things :
Tried loadDataWithBaseURL()
, doesn't work.
Tried all possible scenarios for paths. Nothing worked.
Removed all the scripts from the folder and put them at the root level, and modified links to have no paths, simply file names. Still doesn't work. And this is way too weird.