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

2 Answers

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)

did you had added jar file for import libcore.io.DiskLruCache?

4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest