Start a new topic

Loading ImageResource

Loading ImageResource

I've created an Android library containing Wikitude SDK.

Because Android Libraries don't use Assets folder I've added the ArchitectWorld to the res/raw/ folder.


I'm loading the AR world with the following code (which works fine):




The structure of my AR world is:

- arworld.html

- ade.js

- imagerecognition.js

- image.png



In the imagerecognition.js I'm trying to load the ImageResource and markers with:


var image = new AR.ImageResource("image.png");


The ImageResource keeps giving the error:

"04-03 15:46:53.013: I/ArchitectWebView(10899): Failed to load ImageResouce (1): ???"


When adding an image through html, the right code is <img src="image.png" /> and this works.


I'm using Wikitude SDK 3.3


What is going wrong?


I'm looking into this issue, but we currently don't support loading files from the res/raw folder of a jar file.

I see that we are writing a confusing error message to the log console, we will fix that.

Do you have any suggestion where I can place the HTML/CSS/JS files then?
I prefer to load the files locally, so I don't need a internet connection.

You can load assets from your application assets folder, as in the sample application.

Yes, I know. My Wikitude SDK is integrated in a Android library project. 
Library projects don't use/compile the assets folder.

The problem with resources in the JAR file is that in order to access the files you need to use the absolute path, as explained here:


URLs starting with "file:///android_res/raw" and relative paths seem to work only inside the WebView, not with the Javascript bridge in Wikitude SDK.

I found that it's possible to load assets from your application project(which uses the library) within the library project.
In the Android library I request the arview:


It loads the assets from the application project. The Wikitude SDK can load Images and Targets successfully this way from the application project.

I think for now, this is the best solution possible. I hope the information above may be of use for your team.

Thanks for your information.

Thank you for your information, I'm glad that it worked. I didn't know it could be implemented in that way.

Of course this will only work on Android, but I understand that you have no problems with cross-platform compatibility.


Hi. I 've been receiving an error. I know it is possible to load an image resource from the Android's application directory, but what do i pass as an argument?the abosulte path? E.g./  new AR.ImageResource("assets/marker_idle.png")

new AR.ImageDrawable(new AR.ImageResource("/data/data/com.example.myapp/files/image"), 2.5, {

        zOrder: 0,

        opacity: 1.0,

        onClick: Marker.prototype.getOnClickTrigger(this)


I would like to download resources in the background and load it later when needed.




The path is relative to the HTML file location (see SDK sample application).

If you need to load a file from the android assets directory, you can use the "file:///android_asset/" URL scheme.

I apologize for not being clear. When an Android application is installed, a set of folders are created under an apps data directory based on the app's namespace. E.g. SampleSDK app w/ namespace com.wikitiude.samplesSDK. The set of folders include





Wikitude 3.2 states: "Images can be loaded from any source"

Since I need to load an image dynamically, I cannot retrieve it from the assets directory. I would download the file from a remote server onto the user's phone into the app's data directory. So my question is, how do I appropriately construct the string to retrieve a file in an app's data directory? 

new AR.ImageResource("string/to/apps/data/diretory");

I hope the clarification helps. Thanks

Since your AR world is running inside a WebView, to acess absolute path you need to use a "file://" URL (e.g.: "file:///data/data/")

However, you can load the images directly inside the AR World from a remote URL, they are cached internally and accessed dynamically when needed. 

I've made much progress with your help. Thank you.

Now I'm attempting to test how many images I can load at one time. Unfortunately, I can only load just a few.

Specifically, when loading 5 files from the the "data/data" directory, only the first 3 appeared.
If I switched to files from the "android_asset" directory and I could load more than 3.

Do you have any insight into what the problem might be?



There is a limit on the images you can download simultaneously, if that is what you mean.

Every image is downloaded in a separate thread, and maximal number of active threads is 4. If you start a new download when no threads are available, the request is put in a queue and waits for the first free slot.
Login or Signup to post a comment