question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't create cache in Android

See original GitHub issue

It seems like issue https://github.com/cache2k/cache2k/issues/4 has cropped up again.

I found this recent Stack Overflow post that matches the exact issue I’m seeing as well: https://stackoverflow.com/questions/53583759/java-lang-noclassdeffounderror-when-using-cache2k-on-android

As I’m sure you’re aware, the javax.naming package isn’t available in Android which is the source of the NoClassDefFoundError. The catch block in JndiDefaultNameProvider.java doesn’t actually catch this since Error and its subclasses aren’t actually instances of Exception.

I’ve checked out the master branch and updated this class to also catch and ignore the NoClassDefFoundError but that’s just revealed a similar issue later on in the initialization process when cache2k tries to use classes from the java.lang.management package:

2019-02-12 22:58:07.442 13788-13788/? I/Cache2kCoreProviderImpl: cache2k starting. version=1.4-SNAPSHOT
2019-02-12 22:58:07.464 13788-13788/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.bhohler.test, PID: 13788
    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
        at org.cache2k.impl.serverSide.JmxSupport.managerCreated(JmxSupport.java:80)
        at org.cache2k.core.CacheManagerImpl.<init>(CacheManagerImpl.java:115)
        at org.cache2k.core.Cache2kCoreProviderImpl.getManager(Cache2kCoreProviderImpl.java:158)
        at org.cache2k.core.Cache2kCoreProviderImpl.getManager(Cache2kCoreProviderImpl.java:133)
        at org.cache2k.CacheManager.getInstance(CacheManager.java:89)
        at org.cache2k.Cache2kBuilder.config(Cache2kBuilder.java:161)
        at org.cache2k.Cache2kBuilder.name(Cache2kBuilder.java:321)
        at com.bhohler.test.services.retrofit.SpotifyService.<clinit>(SpotifyService.java:38)
        ...

My cache instance is super basic:

public class SpotifyService {
  ...

  private static final Cache<String, Track> trackCache =
      new Cache2kBuilder<String, Track>() {}.name("trackCache")
          .eternal(true)
          .entryCapacity(100)
          .enableJmx(false)
          .build();

  ...

}

It looks like it’s trying to initialize parts of JMX support even though the docs say it’s supposed to be disabled by default? I’m not sure where to go from here.

For what it’s worth, I’m testing on Android 9 (Pie) with a OnePlus 6T.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
cruftexcommented, Mar 8, 2019

@bhohler thanks for the feedback and providing the test code. I will look into that more. Maybe its a good idea to release a android version with proguard rules already applied.

0reactions
cruftexcommented, Aug 8, 2019

Thanks @bhohler for the test project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android java.lang.RuntimeException: Unable to create cache ...
I am writing an app with access to Dropbox. Get the error: E/AndroidRuntime(14800): Caused by: java.lang.RuntimeException: Unable to create ...
Read more >
How to Clear Cache on Android (And When You Should)
How to Clear the Cache on Android Devices · Open Settings and select Storage. · In the resulting list, tap the Apps entry...
Read more >
How to Clear Your Android Cache & Why You Should Do It
Every app creates cached data, and we'll show you how to clear your cache on Android browsers and apps in a few easy...
Read more >
Caching in the Android Build Process | by Sherry Yuan
Since the Android Studio cache stores project structure information, it can get confused if you move files around or create new XML files....
Read more >
How to Clear the Cache on Your Android Phone to Make It ...
Cache needn't be constantly cleared, but a periodic clean out can be helpful. Your apps and web browser store bits of information to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found