'OpenCV: Architecture "aarch64" is not supported for Apple M1, but for Intel it's ok

I have a simple application with tesseract with Kotlin.

It works great on macos intel. But when I try to run it on Apple M1, this error happens:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at nu.pattern.OpenCV$LocalLoader.getInstance(OpenCV.java:328)
    at nu.pattern.OpenCV.loadLocally(OpenCV.java:311)
    at com.tesseract.demo.ApplicationKt.setupOpenCV(Application.kt:63)
    ... 3 more
Caused by: java.lang.UnsupportedOperationException: Architecture "aarch64" is not supported.
    at nu.pattern.OpenCV$Arch.getCurrent(OpenCV.java:92)
    at nu.pattern.OpenCV.extractNativeBinary(OpenCV.java:337)
    at nu.pattern.OpenCV.access$100(OpenCV.java:23)
    at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:317)
    at nu.pattern.OpenCV$LocalLoader.<init>(OpenCV.java:314)
    at nu.pattern.OpenCV$LocalLoader$Holder.<clinit>(OpenCV.java:324)
    ... 7 more

Perhaps there is a possibility to specify os for opencv via a condition? For example: osdetector.os == "osx". Or how else can I solve this problem?

Gradle dependencies for my app:

dependencies {
    implementation("net.sourceforge.tess4j:tess4j:4.5.3")
    implementation("org.openpnp:opencv:4.3.0-2")
}

the function where the error occurs:

private fun setupOpenCV() {
    OpenCV.loadLocally()
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source