Nitrite/Java: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Instant; #12
-
Hi this is my code as your template:
and this is my logcat in android studio:
|
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 12 replies
-
Have you built your app using jdk 8? Somehow java time is not present in your app runtime. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Verify if minSdkVersion is 26 or above. https://developer.android.com/reference/java/time/Instant.html |
Beta Was this translation helpful? Give feedback.
-
On sdk 26 or above is ok. it's on sdk 23 android 6.0.1 |
Beta Was this translation helpful? Give feedback.
-
Have you found this specific version mentioned in nitirte documentation? Could you please point it out? I might need to correct it. The nitrite java library is compatible for api level 19, but potassium nitrite needs api level 26 by default. Having said that, you can bypass that restriction also in case of potassium nitrite. You just have to set a custom nitrite mapper. See the logic here - https://github.com/nitrite/nitrite-java/blob/9afef01caab7a647dd6b43bd147288b8d6264780/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Builder.kt#L130 One of such example is there in junit tests, where threetenbp library is used in place of java time - https://github.com/nitrite/nitrite-java/blob/9afef01caab7a647dd6b43bd147288b8d6264780/potassium-nitrite/src/test/kotlin/org/dizitart/kno2/BackportJavaTimeTest.kt#L40 Create your own |
Beta Was this translation helpful? Give feedback.
-
I advised you to make a custom JacksonFacade by extending open class MyJacksonFacade(modules: Set<Module>? = setOf()) : JacksonFacade(modules) {
override fun createObjectMapper(): ObjectMapper {
val objectMapper = ObjectMapper();
objectMapper.setVisibility(
objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE));
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// or you can use - val objectMapper = super.createObjectMapper(), if no issue
objectMapper.registerModule(NitriteIdModule());
objectMapper.registerModule(KotlinModule())
objectMapper.registerModule(Jdk8Module())
// and whatever modules you need
return objectMapper;
}
}
Next you initialize your db with this facade val db = nitrite {
path = dbPath
nitriteMapper = object : KNO2JacksonMapper(MyJacksonFacade()) {}
} |
Beta Was this translation helpful? Give feedback.
Have you found this specific version mentioned in nitirte documentation? Could you please point it out? I might need to correct it. The nitrite java library is compatible for api level 19, but potassium nitrite needs api level 26 by default.
Having said that, you can bypass that restriction also in case of potassium nitrite. You just have to set a custom nitrite mapper. See the logic here - https://github.com/nitrite/nitrite-java/blob/9afef01caab7a647dd6b43bd147288b8d6264780/potassium-nitrite/src/main/kotlin/org/dizitart/kno2/Builder.kt#L130
One of such example is there in junit tests, where threetenbp library is used in place of java time - https://git…