# NoClassDefFoundError - BasicNDArrayCompressor

**URL:** <https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944>\
**Category:** Uncategorized\
**Created:** [October 25, 2020, 11:56pm UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944 "2020-10-25T23:56:02Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 25, 2020, 11:56pm UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/1 "2020-10-25T23:56:02Z")

</div>

Hello,

I have models trained on PC (windows) beta6 and beta7 lib versions.  
When I try to run those models on Android i receive error:

Caused by: java.lang.RuntimeException: Error loading ND4J Compressors via service loader: No compressors were found. This usually occurs when running ND4J UI from an uber-jar, which was built incorrectly (without services resource files being included)  
at org.nd4j.linalg.compression.BasicNDArrayCompressor.loadCompressors(BasicNDArrayCompressor.java:64)  
at org.nd4j.linalg.compression.BasicNDArrayCompressor.(BasicNDArrayCompressor.java:44)  
…  
java.lang.NoClassDefFoundError: org.nd4j.linalg.compression.BasicNDArrayCompressor  
at org.nd4j.linalg.compression.BasicNDArrayCompressor.getInstance(BasicNDArrayCompressor.java:96)

On Android, i tried to use beta5 and beta6 but same error is thrown.

If models are trained on beta4 or maybe beta5 - I can run them on Android. (I have some models trained long time ago, not sure on which version - beta4 or beta5)

How to run new models on Android?

Thanks on your time,  
Aleksandar

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [October 26, 2020, 12:24am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/2 "2020-10-26T00:24:01Z")

</div>

@lavajaw could you show us your build.gradle?

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 26, 2020, 9:48am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/3 "2020-10-26T09:48:46Z")

</div>

Sure,

implementation (group: ‘org.deeplearning4j’, name: ‘deeplearning4j-core’, version: ‘1.0.0-beta6’) {  
exclude group: ‘org.bytedeco’, module: ‘opencv-platform’  
exclude group: ‘org.bytedeco’, module: ‘leptonica-platform’  
exclude group: ‘org.bytedeco’, module: ‘hdf5-platform’  
exclude group: ‘org.nd4j’, module: ‘nd4j-base64’  
}  
implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’  
implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’, classifier: “android-arm64”  
implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’  
implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’, classifier: “android-arm64”  
implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’  
implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’, classifier: “android-arm64”

```
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.14'

```

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 27, 2020, 2:02am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/4 "2020-10-27T02:02:36Z")

</div>

@agibsonccc any news?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [October 27, 2020, 2:22am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/5 "2020-10-27T02:22:19Z")

</div>

@lavajaw first off, could you upgrade to beta 7 with the later javacpp versions as well?

@saudet can help you a bit more with android here.

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 27, 2020, 2:24am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/6 "2020-10-27T02:24:11Z")

</div>

Well with beta7 we have this problem:

> [@Upgrade to beta7 - UnsatisfiedLinkError on Android](https://community.konduit.ai/t/upgrade-to-beta7-unsatisfiedlinkerror-on-android/919/5):
>
> @lavajaw for now use snapshots… we’re not sure about a release yet. Maybe within the next month or so, but we still have a few features to work on here. We won’t do a release just for a minor bug fix or 2. Definitely by the end of the year.

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 27, 2020, 2:11pm UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/7 "2020-10-27T14:11:18Z")

</div>

@agibsonccc @saudet Sorry guys, but I need to push you, because my next release depends on this. What I can try in this situation? Any workaround to run beta7 on Android?

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [October 27, 2020, 10:16pm UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/8 "2020-10-27T22:16:19Z")

</div>

If you bundle `libc++_shared.so` in your app, it should work with beta7.

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 27, 2020, 11:19pm UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/9 "2020-10-27T23:19:24Z")

</div>

I tried that and application can run now, but anyway if I use new models trained on beta7 or beta6 its throw error - java.lang.NoClassDefFoundError: org.nd4j.linalg.compression.BasicNDArrayCompressor.  
@saudet

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [October 28, 2020, 12:04am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/10 "2020-10-28T00:04:05Z")

</div>

Yeah, DL4J hasn’t been designed too much with backward compatibility in mind. You might need to resave your models to get them working. Among other things, since you’re using “compressors”, you’ll need to remove those and replace them with NDArrays of the right data type. In any case, ideally, it should be able to load them anyway, so please file an issue about it! Thanks

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [October 28, 2020, 12:21am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/11 "2020-10-28T00:21:36Z")

</div>

> [@saudet](#):
>
> You might need to resave your models to get them working. Among other things, since you’re using “compressors”, you’ll need to remove those and replace them with NDArrays of the right data type.

@saudet Sorry, but can you explane how to do it?  
I just checked, old model and new model use same arhitecture (DenseNet example). Diferences are in :  
Activation - leakyRelu vs swish  
Regularization - none vs weightDecay  
Updater - Adam vs Nesterovs

---

<div class="post-metadata">

**Author:** ![saudet](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/saudet/32/69_2.png) [@saudet](https://community.konduit.ai/u/saudet)\
**Post date:** [October 28, 2020, 1:07am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/12 "2020-10-28T01:07:18Z")

</div>

Does it work on the desktop? If it works with Java SE, it’s probably your version of Android Studio that’s stripping files it shouldn’t be. Make sure all resources for DL4J are found in the final APK.

---

<div class="post-metadata">

**Author:** ![koushik.ragavendran](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@koushik.ragavendran](https://community.konduit.ai/u/koushik.ragavendran)\
**Post date:** [August 4, 2021, 10:09am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/13 "2021-08-04T10:09:23Z")

</div>

I had the same issue. Please verify if NDArrayCompressor resource file is added to META-INF/services of nd4j jar file, NDArrayCompressor resource should contain the implementation of NDArrayCompressor interface. And also set the context loader for all threads with current class’s class loader while performing this operation.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 4, 2021, 10:41am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/14 "2021-08-04T10:41:33Z")

</div>

@koushik.ragavendran actually yes it’s right here: [deeplearning4j/org.nd4j.linalg.compression.NDArrayCompressor at master · eclipse/deeplearning4j · GitHub](https://github.com/eclipse/deeplearning4j/blob/master/nd4j/nd4j-backends/nd4j-backend-impls/nd4j-native/src/main/resources/META-INF/services/org.nd4j.linalg.compression.NDArrayCompressor)

it’s been there for years. Not sure what the issue could be here. It’s likely a classpath issue or the way you’re including resources in an uber jar.

---

<div class="post-metadata">

**Author:** ![koushik.ragavendran](https://avatars.discourse-cdn.com/v4/letter/k/59ef9b/32.png) [@koushik.ragavendran](https://community.konduit.ai/u/koushik.ragavendran)\
**Post date:** [August 4, 2021, 11:02am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/15 "2021-08-04T11:02:28Z")

</div>

@agibsonccc Yes it is there. My answer was related to way it is included to uber jar and also setting right context class loader so that service loader can find the resource and use the implementation.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 4, 2021, 11:05am UTC](https://community.konduit.ai/t/noclassdeffounderror-basicndarraycompressor/944/16 "2021-08-04T11:05:24Z")

</div>

> [@koushik.ragavendran](#):
>
> s included to

@koushik.ragavendran I see. The classloader part is a great point. Note that in dl4j, you can actually set the classloader we use now in 1.0.0-M1 and newer. You can call Nd4jClassLoading.setClassLoader(…) now which may help the situation here as well.

If you do use that, just make sure to set the classloader you want to use before calling any Nd4j.create(…) like methods. Otherwise that will initialize the nd4j backend.
