kyonifer / koma

A scientific computing library for Kotlin. https://kyonifer.github.io/koma
Other
270 stars 23 forks source link

Getting No Matrix Factories Available when in release mode only #105

Closed brianbolze closed 3 years ago

brianbolze commented 3 years ago

Context We have an Android app built in Kotlin and we've split our algorithms layer into a separate Android Project. We import that as a dependency using Gradle using the following code:

In build.gradle:

dependencies {
    ...
    implementation project(':algos-android')
}

This algos-android project has koma as its own dependency defined in the algos-android project's build.gradle file as follows:

dependencies {
    ...
    implementation group: "com.kyonifer", name:"koma-core-ejml", version: "0.12"
}

Issue This works completely fine when running the app in a debug mode (defined in buildTypes in the build.gradle). However, when running in release mode, we are seeing an error at runtime when our algorithms layer tries to use koma. Specifically, when trying to create Double Matrices.

The following error shows up in the console:

java.lang.IllegalStateException: No double matrix factories available. (Did you forget to import a koma-core implementation?)

Has anyone run into issues like this before? We're stuck!!

Things We've Tried Moving all of the files from our algos-android project directly into the main project and importing koma directly in the main project's gradle.build file. Didn't work.

Environment

brianbolze commented 3 years ago

We were finally able to track down the issue and resolve this with the following addition to the proguard-rules.pro file:

-keep class koma.** { *; }

We were able to find that since the Matrix factory classes are inflated in koma sources using reflection, proguard considered them as unused and simply deleted them from the release build.

Note: If you see this and make this fix, don't forget to Clean Project before running.