Can't create cache in Android
See original GitHub issueIt 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:
- Created 5 years ago
- Comments:7 (5 by maintainers)
@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.
Thanks @bhohler for the test project.