[FIXED] How to fix gradle task ':app:mergeDebugJniLibFolders' in flutter gradle build for opencv native with NDK?

Issue

I’m setting up a new flutter app and I want to add opencv native (c++) plugin using NDK.

I’ve installed and configured OpenCV and NDK (using differents tutorials) and I got this error while I’m trying to build my project (flutter run):

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugJniLibFolders'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or -- 
debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 31s
Finished with error: Gradle task assembleDebug failed with exit code 1

I don’t know where it come from, there is no ‘task’ mergeDebugJniLibFolders in my build.gradle from my app.
I can’t run flutter with specified arguments : it make errors.

Solution

I found a solution !

I get in my build.gradle those lines:

sourceSets {
    main {
        jniLibs.srcDirs = ['src/main/libs']
        java.srcDirs = ['src']
        ...
    }
 }

So I decided to open the src/main/libs file which contain only

../../../../OpenCV-Andoid-sdk/native/libs/

… a wrong path that should be :

../../../../sdk/native/libs/

I put the corect path into the gradle file respecting the new relative path :

sourceSets {
    main {
        jniLibs.srcDirs = ['../../sdk/native/libs/']
        java.srcDirs = ['src']
        ...
    }
 }

And now it compile perfectly ! What a tricky error on which I spend 6 evenings…

Answered By – Jérémy

Answer Checked By – Mary Flores (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published