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

Android 6.0: Load 32-bit OpenCV library on 64-bit arch #5862

Closed
jtkac opened this issue Dec 22, 2015 · 13 comments
Closed

Android 6.0: Load 32-bit OpenCV library on 64-bit arch #5862

jtkac opened this issue Dec 22, 2015 · 13 comments

Comments

@jtkac
Copy link

jtkac commented Dec 22, 2015

Hello,

So I was trying to use:
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
and only include 32-bit libraries in my local jniLibs folder in hopes that my application would recognize that it is supposed to load on a 32-bit platform instead of a 64-bit platform. After a couple days of research I had the best fitting solution to only include 32-bit libraries but OpenCVLoader still tried to load a 64-bit framework and instead of gettings the error that this is a 32-bit library in a 64-bit application, I was getting the opposite figurehead.

I guess my issue/requested fix would be to allow the user to explicitly state whether they want to load a 64-bit platform or a 32-bit platform or to detect local jni files to load as necessary through OpenCVLoader's code.

Thank you for your time and consideration,

Koala

@alalek
Copy link
Member

alalek commented Dec 22, 2015

Please provide more details.
Where you get OpenCV? How did you build? What options are used? Do you have OpenCV manager?
How did you get both 32-bit and 64-bit versions?

Did you try this code for OpenCV loading?
https://github.com/Itseez/opencv/blob/231685133ead7a8b2a4777ff6fa1427d8acf4ba4/samples/android/tutorial-1-camerapreview/src/org/opencv/samples/tutorial1/Tutorial1Activity.java#L79-L85

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

Pardon me

I am using OpenCV for Android
The steps I took to install OpenCV were:

  1. download the library (3.0)
  2. In Android Studio: File ->New -> Import Module -> OpenCV-3.0.0-android-sdk -> sdk -> java
  3. Right click project -> Module Settings -> app -> Dependencies -> + -> Module Dependency -> OpenCV
  4. Created Folder jniLibs under app -> src -> main
  5. Took contents from OpenCV 3.0's sdk -> native -> libs and pasted there
  6. Implemented a BaseLoaderCallback
  7. Called OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
  8. Ensured the gradle.build targets, build tools, and minimum were the same in the OpenCV lib

I want to use another library that is only 32 bit. Android 6 searches the abi for 64-bit libraries first and if the device finds a 64-bit library, it loads that library and cannot also load 32-bit libraries.

Android 6 can load 32-bit libraries so long as that is all the device loads. They cannot mix.
So without a way to mix libraries (which is just not possible) I must have the originally loaded OpenCV libraries as 32-bit libraries.

What I am asking is if a feature could be implemented to allow developers the explicit statement of what bit format OpenCV loads. It automatically detects and searches for 64-bit when both formats are possible but if it is desired to omit 64 bit libraries, I should be able to specify to OpenCVLoader's Abi to only load from armeabi or armeabi-v7a.

Thank you again and hopefully that will clarify what I am asking,

Koala

@alalek
Copy link
Member

alalek commented Dec 22, 2015

Thanks! Problem is more clear now.

Did you try to remove/ignore "invalid" 64-bit library folders from native/libs (OpenCV for Android)? Does it work?

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

Thank you for the quick reply,

So far I have just tried removing them but it results in the following error:
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/org.opencv.engine-1/lib/arm64/libopencv_java3.so" is 64-bit instead of 32-bit

so having removed them is detecting that a 32-bit version should be loaded but the loader is looking in a folder that I haven't even got included

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

the folders I have included from the native -> libs are:
armeabi
armeabi-v7a
mips
x86

I have also tried cleaning and rerunning my application

@alalek
Copy link
Member

alalek commented Dec 22, 2015

  1. Remove "OpenCV manager" application from your device. Received path is from this app.
  2. Check this loading scheme:
    https://github.com/Itseez/opencv/blob/231685133ead7a8b2a4777ff6fa1427d8acf4ba4/samples/android/tutorial-1-camerapreview/src/org/opencv/samples/tutorial1/Tutorial1Activity.java#L79-L85
    This scheme will try to use libopencv_java3.so from your "libs".

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

Well although this is progress, it is for some reason not searching for libopencv_java3.so but instead libopencv_java.so and throwing a different unsatisfiedlinkerror

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

There we go
I edited statichelper to contain opencv_java3 opposed to opencv_java

@alalek
Copy link
Member

alalek commented Dec 22, 2015

It is already fixed in OpenCV 3.1.0: 83b2621

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

:/ must have missed it by a couple days... I'll update to the new version

Pardon the waste of time

@jtkac
Copy link
Author

jtkac commented Dec 22, 2015

Everything is compiling correctly and updating to the new version just made it so I wasn't manually altering the files!

To you I say Kudos and thank you.

This issue is resolved.

@alalek
Copy link
Member

alalek commented Dec 23, 2015

Thanks for update.

There are no plans to add this feature into OpenCV Manager (because problem is very specific and can be resolved in other way).

@gaochunchun
Copy link

Thanks. @alalek

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

4 participants