cache2k
看起来很棒,我真的想在我的应用中使用它来缓存对象,我得到了java.lang.NoClassDefFoundError
:
请参阅下面的堆栈跟踪:
12-02 19:09:43.421 25543-25543/uk.whitecrescent.waqti E/AndroidRuntime: FATAL EXCEPTION: main
Process: uk.whitecrescent.waqti, PID: 25543
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/InitialContext;
at org.cache2k.impl.serverSide.JndiDefaultNameProvider.registerCache2kExtension(JndiDefaultNameProvider.java:37)
at org.cache2k.core.Cache2kCoreProviderImpl.registerExtensions(Cache2kCoreProviderImpl.java:79)
at org.cache2k.core.Cache2kCoreProviderImpl.<init>(Cache2kCoreProviderImpl.java:57)
at java.lang.Class.newInstance(Native Method)
at org.cache2k.spi.SingleProviderResolver.resolve(SingleProviderResolver.java:110)
at org.cache2k.spi.SingleProviderResolver.resolve(SingleProviderResolver.java:82)
at org.cache2k.spi.SingleProviderResolver.resolveMandatory(SingleProviderResolver.java:64)
at org.cache2k.CacheManager.<clinit>(CacheManager.java:54)
at org.cache2k.CacheManager.getInstance(CacheManager.java:88)
at org.cache2k.Cache2kBuilder.config(Cache2kBuilder.java:160)
at org.cache2k.Cache2kBuilder.enableJmx(Cache2kBuilder.java:758)
at uk.whitecrescent.waqti.model.persistence.Caches.<clinit>(Caches.kt:74)
...
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.InitialContext" on path: DexPathList
我知道其原因是因为
cache2k
想要使用javax.naming
而不是在Android中,实际上它是在所需的此类中。import org.cache2k.CacheManager;
import org.cache2k.spi.Cache2kExtensionProvider;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
* @author Jens Wilke; created: 2014-10-10
*/
public class JndiDefaultNameProvider implements Cache2kExtensionProvider {
@Override
public void registerCache2kExtension() {
try {
Context ctx = new InitialContext();
ctx = (Context) ctx.lookup("java:comp/env");
String _name =
(String) ctx.lookup("org.cache2k.CacheManager.defaultName");
if (_name != null) {
CacheManager.setDefaultName(_name);
}
} catch (Exception ignore) {
}
}
}
build.gradle
看起来像这样ext.cache2kVersion = '1.2.0.Final'
implementation "org.cache2k:cache2k-api:$cache2kVersion"
implementation "org.cache2k:cache2k-base-bom:$cache2kVersion"
implementation "org.cache2k:cache2k-core:$cache2kVersion"
我尝试让最底端的
runtimeOnly
无效。我什至尝试下载
javax.naming
jar,只是想让它依赖更多内容。我敢肯定这只是一个愚蠢的错误,但我似乎找不到它!
最佳答案
很抱歉,很长一段时间以来,您的回应并让您失望。
cache2k罐子很小,因此我决定放弃以制造更多的小罐子。这意味着jar中包含了JMX支持。在此处记录:https://github.com/cache2k/cache2k/issues/80
为了使其再次在Android上运行,我提供了proguard规则,该规则排除了JMX支持。在此处的文档中查看:
https://cache2k.org/docs/latest/user-guide.html#android
让我知道是否对您有帮助,请问是否有其他问题。