Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated files copied in APK #353

Closed
3dm1 opened this issue Mar 9, 2016 · 48 comments
Closed

Duplicated files copied in APK #353

3dm1 opened this issue Mar 9, 2016 · 48 comments

Comments

@3dm1
Copy link

3dm1 commented Mar 9, 2016

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?

@saudet
Copy link
Member

saudet commented Mar 10, 2016

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

@3dm1
Copy link
Author

3dm1 commented Mar 10, 2016

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.

@saudet
Copy link
Member

saudet commented Mar 10, 2016

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

@lykhonis
Copy link

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?

@saudet
Copy link
Member

saudet commented Mar 24, 2016

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

@djamb
Copy link

djamb commented Apr 18, 2016

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'
    }
}

@udeysri
Copy link

udeysri commented May 6, 2016

//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 ...

@saudet
Copy link
Member

saudet commented May 19, 2016

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

@ArjunAchatz-MF
Copy link

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

@evaliyev
Copy link

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

@TharakaDamayantha
Copy link

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

@rajkumarmishra
Copy link

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`

@pahdo
Copy link

pahdo commented Feb 8, 2017

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`

@josenefi
Copy link

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

@rajkumarmishra
Copy link

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

@TharakaDamayantha
Copy link

TharakaDamayantha commented Feb 12, 2017

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.

@eastom
Copy link

eastom commented Feb 14, 2017

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

@kongqw
Copy link

kongqw commented Mar 3, 2017

@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.

@minhtridn2001
Copy link

@eastom Thank you so much 👍

@FongMi
Copy link

FongMi commented Sep 4, 2017

@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

@skpaik
Copy link

skpaik commented Jan 17, 2018

Use the following code block

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

@nicemanis
Copy link

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'

@dancingpipi
Copy link

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?

@nicemanis
Copy link

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

@jasonakon
Copy link

jasonakon commented Sep 27, 2020

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'

@saudet
Copy link
Member

saudet commented Sep 27, 2020

@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.

@sieme97
Copy link

sieme97 commented Sep 28, 2020

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?

@sieme97
Copy link

sieme97 commented Sep 28, 2020

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

@saudet
Copy link
Member

saudet commented Oct 1, 2020

@sieme97 What errors are you getting?

@ianlienfa
Copy link

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
           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)
    

@saudet
Copy link
Member

saudet commented Jan 29, 2021

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.

@ianlienfa
Copy link

got it, thanks for replying!

@ianlienfa
Copy link

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 !

@saudet
Copy link
Member

saudet commented Jan 31, 2021

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

@ianlienfa
Copy link

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!

@saudet
Copy link
Member

saudet commented Feb 2, 2021

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

@ianlienfa
Copy link

Will do! Let me first tidy it up!

@saudet
Copy link
Member

saudet commented Jun 21, 2021

For a working example, I think we can now refer to the JavaCV-android-example sample project that @GZaccaroni has updated:
https://github.com/bytedeco/sample-projects/tree/master/JavaCV-android-example
If anyone is still having issues with this, please let us know! If not, I think we can close this issue.

@ianlienfa
Copy link

Actually I have a project file importing via jar files though its a bit bulky, I can still upload it if needed.
Sorry for the late response btw

@saudet
Copy link
Member

saudet commented Jul 14, 2021

I think we can finally close this issue. After fixing a few small issues, I've confirmed that the updated JavaCV-android-example sample project works great out of the box with JavaCV 1.5.5, so if anyone is still having issues getting JavaCV running on Android, please start from here: https://github.com/bytedeco/sample-projects/tree/master/JavaCV-android-example

@saudet saudet closed this as completed Jul 14, 2021
@saudet
Copy link
Member

saudet commented Nov 30, 2021

Furthermore, using Gradle to extract JAR files automatically as per issue #1117 (comment) also prevents unnecessary stuff from getting into the final APK or AAB files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests