Select to view content in your preferred language

NoClassDefFound for CoreSpatialReference in Unit Tests

713
2
Jump to solution
06-07-2023 04:41 AM
padmalcom
Frequent Contributor

Hi, we have several unit tests in our app (based on 200.1.0). When I create a point as shown below, I get a NoClassDefFound for CoreSpatialReference.

Point(
point.latitude,
point.longitude,
SpatialReference(MapConstants.EPSG_CODE)
)

Do I have to do sth special during the setup of the build.gradle so that the classes are avaiable during testing?

The exact error is:

Could not initialize class com.arcgismaps.internal.jni.CoreSpatialReference
java.lang.NoClassDefFoundError: Could not initialize class com.arcgismaps.internal.jni.CoreSpatialReference
at com.arcgismaps.geometry.SpatialReference.<init>(SpatialReference.kt:210)
at de.bwi.kvib.mobile.core.network.model.vorgang.FeatureVorgangRouteFormKt.toPolylines(FeatureVorgangRouteForm.kt:30)

Edit: When I create a point without a SpatialReference, I get the following error:

java.lang.NoClassDefFoundError: Could not initialize class com.arcgismaps.internal.jni.CorePoint

This shows that my setup seems to be incorrect but I followed the steps from here:

https://developers.arcgis.com/kotlin/install-and-set-up/

Edit 2: Found a similar thread from two years ago. The solution proposes to do a ArcGISRuntime.initialize() but that class does not exist anymore. What is nowaday's equivalent?

https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/can-t-unit-test-with-esri-s-a...

0 Kudos
1 Solution

Accepted Solutions
HudsonMiears
Esri Contributor

Hi @padmalcon. Are you running these tests as non-instrumented tests? Unfortunately the SDK cannot be tested using non-instrumented tests, they must be put in the `androidTest` folder.

View solution in original post

0 Kudos
2 Replies
HudsonMiears
Esri Contributor

Hi @padmalcon. Are you running these tests as non-instrumented tests? Unfortunately the SDK cannot be tested using non-instrumented tests, they must be put in the `androidTest` folder.

0 Kudos
padmalcom
Frequent Contributor

Hi @HudsonMiears, thanks for your reply, we put the test(s) into the androidTest folder and the jni error disappears. It would be great if such information was provided in the documentation.

0 Kudos