Benoit Benoit - 5 months ago 102
Android Question

import libcore.io.DiskLruCache failed

I want to use DiskLruCache in my project as explained in Caching Bitmaps, but cannot import the correct lib.

Where can I find the jar containing this class ?

As suggested in similar questions, I added the following line to my

build.gradle
:

dependencies {
...
compile 'org.robovm:robovm-rt:+'
}


Gradle seems to find the lib, but my code still does not compile :

package com.example ;

import android.util.LruCache;

import libcore.io.DiskLruCache;

public class ObjectCache {

private LruCache<String, String> memoryCache;
private DiskLruCache diskLruCache ;

public ObjectCache(int cacheSize) {
memoryCache = new LruCache<String, String>(cacheSize);
diskLruCache = null ;
}
}


It fails with following errors :

Error:(5, 18) error: package libcore.io does not exist
Error:(10, 13) error: cannot find symbol class DiskLruCache

Answer

When you use '+' (plus sign), it appears that gradle uses the latest available version of the lib. In this case, it is 1.14.0. But DiskLruCache is no more present in this version.

Moreover between version 0.2 and 1.0.0, it was moved from package libcore.io to package com.android.okhttp.internal.

Conclusion:

It all depends on what version of robovm you user :

  • 0.0.2 or 0.0.4 : import libcore.io.DiskLruCache
  • 1.0.0 to 1.13.0 : import com.android.okhttp.internal.DiskLruCache
  • 1.14.0 to ... : (no more DiskLruCache)