0

WebView is being used with local .html file which in turn includes local .js files. Where to put .html, .js and probably other similar files in an Android Studio project so that IDE would show me these files and IDE plugins such as auto-complete would work?

Things I have tried:

  1. Assets folder. Works but it is not recommended

as the assets cannot (and shouldn't) be updated once the app has been packaged and signed

but doesn't that mean that the next time I build .apk file and the application is beings installed the assets will be replaces with anything that was in the assets folder in the new .apk build?

  1. res/raw. Got that idea from here. Looks like it will work for .html files but not for .js as I am getting compilation error because of .js file: '-' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore

  2. /drawables/raw. Does not seem to work at all although it was suggested here. First thing - Android Studio does not even show these files if you put them in that directory (tried renaming to /drawable/raw, note not a plural name) so that is an issue for me even if compilation would succeed. Second - if I put .html and .js files in drawable I get: The file name must end with .xml or .png

  3. Tried putting them in one of Java packages but could not get those files because it seems Android Java can not access files like plain Java does.

user435421
  • 859
  • 2
  • 13
  • 31
  • Enlighten me. What are you trying to achieve by statically packaging html? – Hiro Mar 01 '21 at 15:26
  • 1
    Is this supposed to be an offline app? –  Mar 01 '21 at 15:27
  • Implementing an offline map application with OpenLayers since no other free and acceptapble framework would give me the functionality I need. – user435421 Mar 01 '21 at 15:27
  • I updated my previous comment. It's an offline application – user435421 Mar 01 '21 at 15:29
  • 1
    What if you package the script files using webpack so you end up with a single bundle file, then put it inline into your HTML document? Also, as far as I'm concerned, "the assets cannot be updated" doesn't sound like a deal breaker. When you publish an update to your app, what's keeping you from also updating the HTML / JS assets before you build the updated version? I assume that statement was based on coming from an app that uses online HTML, which can of course be updated independently of the app. –  Mar 01 '21 at 15:33
  • Your suggestion with `webpack` might work. About the `assets`: it is my first `Android` application so I find the `assets` folder solution to be an issue only because it was said to be so in a couple of `stackoverflow` posts - other than that I have no issues with `assets` folder. – user435421 Mar 01 '21 at 15:37

0 Answers0