Javacv: Duplicated files copied in APK

Created on 9 Mar 2016  ·  44Comments  ·  Source: bytedeco/javacv

After updating to gradle 2.10 I started getting the following error for opencv and ffmpeg:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForCamioDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties
    File1: /.../.gradle/caches/modules-2/files-2.1/org.bytedeco.javacpp-presets/opencv/2.4.10-0.10/a52a775a3d2d578823f86f1c9a347501bc39d9d2/opencv-2.4.10-0.10.jar
    File2: /.../.gradle/caches/modules-2/files-2.1/org.bytedeco.javacpp-presets/opencv/2.4.10-0.10/2c3aef96adc0bdc11519b79d26603716e8a961c3/opencv-2.4.10-0.10-android-arm.jar

In order to ignore them, I used pickFirst to prevent duplication.

packagingOptions {
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
}

Is this the right way to do it or some other approach is advisable?

enhancement help wanted

Most helpful comment

//Exclude duplicates
android {
   ..............
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    }
}

dependencies {
    compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'
}

This worked for me with gradle:2.0.0 ...

All 44 comments

Not sure, why are you getting duplicates? What does your build file looks like?

I'm adding them with gradle as follows:

compile group: 'org.bytedeco', name: 'javacv', version: '0.10'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.10-0.10', classifier: 'android-arm'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.5.1-0.10', classifier: 'android-arm'

I know its outdated and plan to upgrade to 1.0 as soon as possible.

Yeah, try with 1.1 and let me know if that still happens. Thanks!

Getting same error. My gradle is

compile 'org.bytedeco:javacv:1.1'
compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:android-x86' // android-arm
compile 'org.bytedeco.javacpp-presets:ffmpeg:2.8.1-1.1:android-x86' // android-arm

and error:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDevDebug'. com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties
File1: .../modules-2/files-2.1/org.bytedeco.javacpp-presets/opencv/3.0.0-1.1/902947d7faea1294a98e7c1aea76a581fe558a76/opencv-3.0.0-1.1.jar
File2: .../modules-2/files-2.1/org.bytedeco.javacpp-presets/opencv/3.0.0-1.1/a9b05f9ad791eaf0c4f77aa8fa73b3f2a7c179e5/opencv-3.0.0-1.1-android-x86.jar

I've tried to exclude opencv and ffmpeg modules from javacv dependency, but then getting class not found. I am trying to test it like this:

try {
    FFmpegFrameRecorder.tryLoad();
} catch (FrameRecorder.Exception e) {
    throw new RuntimeException(e);
}

Any ideas?

Looks like a problem with Gradle... What do the Gradle guys say?

Reorder your packages

android{
    //Exclude duplicates
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    }
}
//Exclude duplicates
android {
   ..............
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
        pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    }
}

dependencies {
    compile group: 'org.bytedeco', name: 'javacv', version: '0.11'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '2.4.11-0.11', classifier: 'android-x86'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '2.6.1-0.11', classifier: 'android-x86'
}

This worked for me with gradle:2.0.0 ...

Could someone talk with the Gradle developers about what we should be doing with this?

@udayasri @djamb .. your post worked for me as a solution for now. This is with Android Studio 2.1.1.

Have similar issue with SBT:

[error] (android:apkbuild) com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties [error] File1: /home/evaliyev/Projects/App/lib/ffmpeg.jar [error] File2: /home/evaliyev/.ivy2/cache/org.bytedeco.javacpp-presets/ffmpeg/jars/ffmpeg-3.0.2-1.2.jar [error] File3: /home/evaliyev/Projects/App/lib/ffmpeg-android-arm.jar

i added those lines as 3dm1 and udayasiri suggested but still the same type of error comes in a different way :( :( duplicate file copied ....

I am also facing the same issue even after installing manually or directly in Gradle.

`Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib
File1: C:\Users\Rajnish.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\libdc1394\2.2.4-1.3\f1498dacc46162ab68faeb8d66cf02b96fe41c61\libdc1394-2.2.4-1.3-macosx-x86_64.jar
File2: C:\Users\Rajnish.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\libfreenect\0.5.3-1.3\736d65a3ef042258429d8e7742128c411806b432\libfreenect-0.5.3-1.3-macosx-x86_64.jar`

Just wanted to add that I'm encountering the same issue:

`Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib
File1: /Users/daniel/.gradle/caches/modules-2/files-2.1/org.bytedeco.javacpp-presets/libdc1394/2.2.4-1.3/f1498dacc46162ab68faeb8d66cf02b96fe41c61/libdc1394-2.2.4-1.3-macosx-x86_64.jar
File2: /Users/daniel/.gradle/caches/modules-2/files-2.1/org.bytedeco.javacpp-presets/libfreenect/0.5.3-1.3/736d65a3ef042258429d8e7742128c411806b432/libfreenect-0.5.3-1.3-macosx-x86_64.jar`

The same problem, any idea?

:Gradle tasks [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug]

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib
File1: C:\Users\DLNLab.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\libfreenect\0.5.3-1.3\736d65a3ef042258429d8e7742128c411806b432\libfreenect-0.5.3-1.3-macosx-x86_64.jar
File2: C:\Users\DLNLab.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\libdc1394\2.2.4-1.3\f1498dacc46162ab68faeb8d66cf02b96fe41c61\libdc1394-2.2.4-1.3-macosx-x86_64.jar

I don't know what is the solution for this.
But there is another way to setup JavaCV and use it in your android application, i followed the instruction and now it is running with no trouble. Install javacv manually follow as instructed:
https://github.com/bytedeco/javacpp-presets/wiki/The-UnsatisfiedLinkError-X-File-%28a-real-experience%29
https://www.bountysource.com/issues/38410416-aar-dependency-not-working

ok problem solved for me . I just followed following steps

first i updated my android studio and it is around 200 mb i guess. anyway keep the INTERNET connection on even after the update. and then

  1. goto app/libs in your project folder
    2.Copy javacpp.jar, javacv.jar, opencv.jar, and ffmpeg.jar into that folder.
    3.Extract all the *.so files from opencv-android-arm.jar and ffmpeg-android-arm.jar directly into the newly created "app/src/jniLibs/armeabi" folder, without creating any of the subdirectories found in the JAR files.
    (To get so files from those jar files open those files using winrar and goto libs/armeabi folder )

4.navigate to Project > Properties > Java Build Path > Libraries and click "Add JARs...". (you can click "app" in your android project view and press f4 and go to dependencies , click plus sign in corner and click file dependencies and proceed)
Select all of javacpp.jar, javacv.jar, opencv.jar, and ffmpeg.jar from the "libs" folder i mentioned before.

check my updated gradel script. not sure whether this is needed or not.
` buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
    exclude 'META-INF/services/javax.annotation.processing.Processor'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
    pickFirst  'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'

}`

Now my javacv code is running in android. Thanks who wrote the instructions here.
https://groups.google.com/forum/#!topic/javacv/36BgmoZA8aU
The above steps are taken from this link.

Successful solution for Duplicate files exception as below. MUST use the correct duplicateFileException file name 'org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib'.

packagingOptions {
pickFirst 'org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib'
/exclude 'META-INF/services/javax.annotation.processing.Processor'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
/
}

My exception before solved as below:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/bytedeco/javacpp/macosx-x86_64/libusb-1.0.dylib
File1: C:\Users\luoqg.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\libdc1394\2.2.4-1.3\f1498dacc46162ab68faeb8d66cf02b96fe41c61\libdc1394-2.2.4-1.3-macosx-x86_64.jar
File2: C:\Users\luoqg.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\libfreenect\0.5.3-1.3\736d65a3ef042258429d8e7742128c411806b432\libfreenect-0.5.3-1.3-macosx-x86_64.jar

@saudet my gradle file like this

apply plugin: 'com.android.library'
android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 25

//        ndk {
//            // 设置支持的 SO 库构架
//            abiFilters 'armeabi'
//            // , 'armeabi-v7a'// , 'arm64-v8a', 'x86', 'x86_64', 'mips', 'mips64'
//        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.properties'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/opencv/pom.xml'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.properties'
        pickFirst 'META-INF/maven/org.bytedeco.javacpp-presets/ffmpeg/pom.xml'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile group: 'org.bytedeco', name: 'javacv', version: '1.3.1'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.1.0-1.3', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.1.0-1.3', classifier: 'android-x86'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-x86'
}

grade version 2.2.3 is no problem, but then I update grade to 2.3.0,it's not work, show this

Error:Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK lib/armeabi/libjniavcodec.so
    File1: /Users/kongqingwei/.gradle/caches/modules-2/files-2.1/org.bytedeco.javacpp-presets/ffmpeg/3.2.1-1.3/a529ed8c20539530ca4f422b0567fa03e7bf0b44/ffmpeg-3.2.1-1.3-android-arm.jar
    File2: /Users/kongqingwei/Workspace/GitHubProjects/KqwFaceDetectionDemo/openCVLibrary2411/build/intermediates/bundles/default/jni

I try to exclude 'lib/armeabi/libjniavcodec.so',but it's one by one.too much.

@eastom Thank you so much 👍

@kongqw Same as here

Error:Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDirekDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK lib/armeabi/libjniavcodec.so
File1: C:\Users\FongMi.gradle\caches\modules-2\files-2.1\org.bytedeco.javacpp-presets\ffmpeg\3.2.1-1.3\a529ed8c20539530ca4f422b0567fa03e7bf0b44\ffmpeg-3.2.1-1.3-android-arm.jar
File2: C:\Users\FongMi\AndroidStudioProjects\direk-app-android-new\facerec\build\intermediates\bundles\default\jni

Use the following code block

android {
    packagingOptions {
        pickFirst 'protobuf.meta'
        }
}

Could someone please update the wiki with this information?
https://github.com/bytedeco/javacpp-presets/wiki
Everyone has write permission!

do we have a solution here? It seems kongqw commented on Mar 2, 2017 's answer doesn't work with grade after 2.3

@YLPeng I'm actually not seeing any such error messages anymore with Android Studio 3.1 and Gradle 4.4. What are you getting exactly?

@saudet I'm getting this error:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> More than one file was found with OS independent path 'org/bytedeco/javacpp/windows-x86/api-ms-win-core-libraryloader-l1-1-0.dll'

@nicemanis Those come from artifacts for Windows, you can remove them.

@nicemanis Those come from artifacts for Windows, you can remove them.

@saudet How can I do that?
I've added it in the app/build.gradle as implementation group: 'org.bytedeco', name: 'javacv-platform', version: '1.4.4'

@saudet I tried excluding it as follows:

implementation(group: 'org.bytedeco', name: 'javacv-platform', version: '1.4.4') {
    exclude group: 'org.bytedeco.javacpp', module: 'windows-x86_64'
}

but it still results in the same error

Managed to get it build after changing the name from javacv-platform to simply javacv

implementation group: 'org.bytedeco', name: 'javacv', version: '1.4.4'

Managed to get it build after changing the name from javacv-platform to simply javacv

implementation group: 'org.bytedeco', name: 'javacv', version: '1.4.4'

@nicemanis is it work?

Managed to get it build after changing the name from javacv-platform to simply javacv

implementation group: 'org.bytedeco', name: 'javacv', version: '1.4.4'

@nicemanis is it work?

It worked for me

For those who have error with :

  • "More than one file was found with OS independent path"
  • couldn't find "libjniavutil.so"

Please refer to this gradle file at link : https://github.com/Karthi96/Video-Recorder-with-Frames-Analysis/blob/master/app/build.gradle

Under android

    splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi'
            universalApk false
        }
    }

Under dependencies:

    implementation group: 'org.bytedeco', name: 'javacv', version: '1.3.2'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-arm'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-x86'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-x86'

@jasonakon Ah, so that splits block is no longer optional? That's good to know. We should probably update some wiki and/or sample projects with that.

For those who have error with :

  • "More than one file was found with OS independent path"
  • couldn't find "libjniavutil.so"

Please refer to this gradle file at link : https://github.com/Karthi96/Video-Recorder-with-Frames-Analysis/blob/master/app/build.gradle

Under android

    splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi'
            universalApk false
        }
    }

Under dependencies:

    implementation group: 'org.bytedeco', name: 'javacv', version: '1.3.2'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-arm'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-x86'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
    implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-x86'

It worked for me. Can you tell me how to use the latest version of JavaCV?

When I try to build with this implementation compile group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.4' , it was throwing some errors.

@sieme97 What errors are you getting?

I've been trying to install both OpenCV java and JavaCV into android studio project, spending me whole day but still getting errors, below I'll show the way I set up the environment.
I'm writing some function in Java, so I also hope to run the code without using the emulator
Would be very appreciated for any help

OpenCV installation and test

So I install OpenCV as a module, so there is a jinLibs file in my app/src/main and a openCVlibrary file inside the project file
image

I test out the OpenCV installation by calling this in mainActivity.kt, it runs normally.
mainActivity.kt

package com.example.testopencv

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import org.opencv.android.OpenCVLoader;

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!OpenCVLoader.initDebug())
            Log.e("OpenCv", "Unable to load OpenCV");
        else
            Log.d("OpenCv", "OpenCV loaded");
        setContentView(R.layout.activity_main)
    }
}

JavaCV library install

build.gradle(app)

dependencies{
  implementation group: 'org.bytedeco', name: 'javacv', version: '1.5.4'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-arm'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-x86'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-x86'
}

Code test

Errors emerged when I started to run this in
MainActivity.kt

package com.example.testopencv

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.example.testopencv.MyImage.ImageGallery
import org.bytedeco.opencv.global.opencv_imgcodecs
import org.bytedeco.opencv.opencv_core.Mat
import org.opencv.android.OpenCVLoader

fun stdLoadImg(filename: String): Mat {
    val from = "/Users/linenyan/Coding/TestOpenCV/app/src/main/java/com/example/testopencv/MyImage/" + filename
    val image = opencv_imgcodecs.imread(from)
    if (image == null) {
        println("stdLoadImg error: img is null.")
        System.exit(-1)
    }
    return image
}

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!OpenCVLoader.initDebug())
            Log.e("OpenCv", "Unable to load OpenCV");
        else {
            Log.d("OpenCv", "OpenCV loaded");
            val image: Mat = stdLoadImg("rex.jpg")
        }
        setContentView(R.layout.activity_main)
    }
}

The error message

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.testopencv, PID: 21385
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libjniopenblas_nolapack.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1300)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
        at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:12)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1190)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
        at org.bytedeco.opencv.global.opencv_imgcodecs.<clinit>(opencv_imgcodecs.java:18)
        at org.bytedeco.opencv.global.opencv_imgcodecs.imread(Native Method)
        at com.example.testopencv.MainActivityKt.stdLoadImg(MainActivity.kt:13)
        at com.example.testopencv.MainActivity.onCreate(MainActivity.kt:28)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "libopenblas.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123) 
        at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:12) 
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:454) 
        at org.bytedeco.javacpp.Loader.load(Loader.java:1190) 
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123) 
        at org.bytedeco.opencv.global.opencv_imgcodecs.<clinit>(opencv_imgcodecs.java:18) 
        at org.bytedeco.opencv.global.opencv_imgcodecs.imread(Native Method) 
        at com.example.testopencv.MainActivityKt.stdLoadImg(MainActivity.kt:13) 
        at com.example.testopencv.MainActivity.onCreate(MainActivity.kt:28) 
        at android.app.Activity.performCreate(Activity.java:8000) 
        at android.app.Activity.performCreate(Activity.java:7984) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

More Info

  • I tried adding
    splits { abi { enable true reset() include 'x86', 'armeabi' universalApk false } }
    metioned above, but I find it making OpenCVLoader unloadable
  • I metioned that I'm writing some Java functions so I would like to test the inside android studio based on the some development environment, running it by pressing the green button on the left side like this:
    截圖 2021-01-29 下午12 07 44
    However, OpenCVLoader.initDebug() always crushes using this method, with the error message showing below
    Exception in thread "main" java.lang.RuntimeException: Stub! at android.util.Log.d(Log.java:29) at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:25) at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:66) at com.example.testopencv.Test.main(Test.java:15)

JavaCV library install

build.gradle(app)

dependencies{
  implementation group: 'org.bytedeco', name: 'javacv', version: '1.5.4'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-arm'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.2.0-1.3', classifier: 'android-x86'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
      implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-x86'
}

You're missing the binaries for OpenBLAS here.

got it, thanks for replying!

Hi, so I followed your instruction and did some search on the web.
I'm now trying to manually install the binaries, while confronting the following errors

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.imagetest, PID: 10166
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libjniopenblas_nolapack.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1300)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
        at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:12)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1190)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
        at org.bytedeco.opencv.global.opencv_imgcodecs.<clinit>(opencv_imgcodecs.java:18)
        at org.bytedeco.opencv.global.opencv_imgcodecs.imread(Native Method)
        at com.example.imagetest.MyImage.ImageGallery.stdLoadImg(ImageGallery.java:119)
        at com.example.imagetest.MainActivity.onCreate(MainActivity.kt:14)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "libopenblas.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123) 
        at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:12) 
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:454) 
        at org.bytedeco.javacpp.Loader.load(Loader.java:1190) 
        at org.bytedeco.javacpp.Loader.load(Loader.java:1123) 
        at org.bytedeco.opencv.global.opencv_imgcodecs.<clinit>(opencv_imgcodecs.java:18) 
        at org.bytedeco.opencv.global.opencv_imgcodecs.imread(Native Method) 
        at com.example.imagetest.MyImage.ImageGallery.stdLoadImg(ImageGallery.java:119) 
        at com.example.imagetest.MainActivity.onCreate(MainActivity.kt:14) 
        at android.app.Activity.performCreate(Activity.java:8000) 
        at android.app.Activity.performCreate(Activity.java:7984) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
I/Process: Sending signal. PID: 10166 SIG: 9

I guess I have to modify the split part of the gradle, but the error still bumps up.
This is my
build.gradle(app)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {H
        applicationId "com.example.imagetest"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    packagingOptions {
        exclude 'META-INF/native-image/macosx-x86_64/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/macosx-x86_64/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/android-x86/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-x86/jnijavacpp/reflect-config.json'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    repositories {
        flatDir {
            dirs("src/main/jniLibs")
        }
    }
    sourceSets {
        main {
            jni {
                srcDirs 'src/main/jniLibs'
            }
        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
            universalApk false
        }
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation fileTree(dir: "src/main/jniLibs", include: ["*.jar"])
}

And this is my file structure:
image

Big Thanks for helping !

I'm afraid you'll need to figure out why those files are not being copied from the JAR files into the APK file.

I solved it!
I deleted the 'armeabi', 'armeabi-v7a' in the inclusion and it worked.
* build.gradle(app)*

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.artfestproject1"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    packagingOptions {
        exclude 'META-INF/native-image/macosx-x86_64/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/macosx-x86_64/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-arm64/jnijavacpp/reflect-config.json'
        exclude 'META-INF/native-image/android-x86/jnijavacpp/jni-config.json'
        exclude 'META-INF/native-image/android-x86/jnijavacpp/reflect-config.json'
    }
    repositories {
        flatDir {
            dirs("src/main/jniLibs")
        }
    }
    sourceSets {
        main {
            jni {
                srcDirs 'src/main/jniLibs'
            }
        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'arm64-v8a'
            universalApk false
        }
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation fileTree(dir: "src/main/jniLibs", include: ["*.jar"])
}

Still got some

E/linker: normalize_path - invalid input: "lib/", the input path should be absolute
W/linker: Warning: unable to normalize "lib/" (ignoring)

in the output, but you mentioned that we can Ignore that in other issue.
Big thanks!

@ianlienfa Please consider updating one of the sample projects like that: https://github.com/bytedeco/sample-projects Thanks!

Will do! Let me first tidy it up!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fif10 picture fif10  ·  3Comments

Maleandr picture Maleandr  ·  3Comments

RaGreen picture RaGreen  ·  4Comments

SenudaJayalath picture SenudaJayalath  ·  3Comments

chrisliu12345 picture chrisliu12345  ·  4Comments