0

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
Community
  • 1
  • 1
Benoit
  • 5,118
  • 2
  • 24
  • 43

2 Answers2

2

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)
Benoit
  • 5,118
  • 2
  • 24
  • 43
0

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

vimal raj
  • 295
  • 1
  • 13
  • This is the exactly the purpose of adding a dependency in build.gradle, i.e. make the jar available to your project. – Benoit Jun 30 '16 at 10:24
  • 1.Put the jar into the libs folder 2.Right click it and hit 'Add as library' 3.Ensure that compile files is in your build.gradle file 4.Do a clean build and then rebuild. 5. click sync with gradle and then run. – vimal raj Jul 01 '16 at 05:51
  • OK but what is the correct jar ? And where is it located ? I will re-phrase my question – Benoit Jul 05 '16 at 14:31
  • http://www.java2s.com/Code/Jar/r/Downloadrobovmrt002jar.htm , from this site you can download the jar file. if it works ,mark it as worked – vimal raj Jul 06 '16 at 05:28