Skip to content

Android, NetBeans, and the Assets directory

Working on an Android app this week, I wanted to add some resources in the assets directory for use in a WebView as described in the SDK docs. I loaded up my project in NetBeans with the cool nbandroid NetBeans plugin for Android development. I built the application, loaded it up in the WebView, and… File not found?

I found a few posts about WebView being unable to open local files, and the need to use a ContentProvider to get around the limitation. Tried that, no luck. So, I eventually expanded the .apk and…  No assets?

I found this post to the nbandroid forum from someone seeing the same issue, and tracked down the problem from there. It turned out to be an issue in the build script generated by nbandroid, and the fix is quite simple.

To fix:

  1. Create a directory called ‘assets’ at your project root (same dir that AndroidManifest.xml lives)
  2. In /nbproject/project.properties, change
    assets.dir=

    to

    assets.dir=assets
    assets.available=true
  3. In /nbproject/build-impl.xml, there is line in the “if=assets.available” target that reads
    <arg value="${asset.dir}"/>
    

    that needs to be changed to

    <arg value="${assets.dir}"/>

That’s it – you should be all set and “file:///android_asset/” should be accessible to your application and contain the contents of your project’s assets directory.

4 Comments

  1. KCW

    This is a bug, Right?

    The plug-in should have created that stuff…

    Posted on 24-Jul-09 at 6:41 am | Permalink
  2. I agree with you…

    Posted on 30-Jul-09 at 3:16 pm | Permalink
  3. Daniele

    Great thread!!!

    works for me

    Posted on 05-Mar-10 at 12:45 pm | Permalink
  4. Anton Bashmakov

    Great post! But I have to note that /nbproject/build-impl.xml will be regenerated every time you change some thing in the project properties. So the changes will be lost. It’s better to create the asset.dir variable in the /nbproject/project.properties, I wrote like this and it’s working :

    assets.dir=assets
    assets.available=true
    asset.dir=assets

    Posted on 06-Aug-10 at 6:38 am | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*

Spam Protection by WP-SpamFree