google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
26.85k stars 5.09k forks source link

build libmediapipe_tasks_vision_image_generator_jni.so standalone for android_arm64, but it depends "libopencv_java3.so" #4891

Open caofx0418 opened 11 months ago

caofx0418 commented 11 months ago

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

None

OS Platform and Distribution

Android13

MediaPipe Tasks SDK version

No response

Task name (e.g. Image classification, Gesture recognition etc.)

image generator

Programming Language and version (e.g. C++, Python, Java)

C++

Describe the actual behavior

dlopen errror

Describe the expected behaviour

run success

Standalone code/steps you may have used to try to get what you need

Add some new interface and build libmediapipe_tasks_vision_image_generator_jni.so standalone for android_arm64, but it depends "libopencv_java3.so"

Is it any compile option to remove "libopencv_java3.so" dependency?

1. build cmd:
bazel build -s -c opt --define MEDIAPIPE_DISABLE_OPENCV=1 --define EXCLUDE_OPENCV_SO_LIB=1 --strip always --config=android_arm64 mediapipe/tasks/java/com/google/mediapipe/tasks/vision/imagegenerator:libmediapipe_tasks_vision_image_generator_jni.so

2. check so dependencies 
readelf -a bazel-bin/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/imagegenerator/libmediapipe_tasks_vision_image_generator_jni.so | grep NEEDED

3.integrate to Android APP with NDK, it's also dlopen failed

Other info / Complete Logs

readelf -a bazel-bin/mediapipe/tasks/java/com/google/mediapipe/tasks/vision/imagegenerator/libmediapipe_tasks_vision_image_generator_jni.so | grep NEEDED

 0x0000000000000001 (NEEDED)             Shared library: [libopencv_java3.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libEGL.so]
 0x0000000000000001 (NEEDED)             Shared library: [libGLESv2.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libandroid.so]
 0x0000000000000001 (NEEDED)             Shared library: [libjnigraphics.so]
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]

integrate to Android APP with NDK, it's also dlopen failed

 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "libopencv_java3.so" not found: needed by /data/app/~~
nrPezi-BGsR3OnrzxYCYyg==/com.google.mediapipe.examples.imagegeneration-gT2ibF4_h5p47u62xJ7TSQ==/lib/arm64/libmediapipe_tasks_vision_image_generator_jni.so in
namespace classloader-namespace
kuaashish commented 11 months ago

Hi @caofx0418,

From the issue description, it appears that you are attempting to use the Image Generator Task in the C++ platform. However, please note that the Image Generator is exclusively available in the Android platform, and customisation is achievable in the Python platform, as explained in our documentation.

Could you kindly outline the specific steps you are following, making reference to the documentation? Additionally, if you are following the documentation, please confirm the Operating System, Android Studio version, Android SDK versions, and indicate whether you are able to run other examples based on the Android steps provided here.

This information will assist us in reproducing and gaining a better understanding of the issue on our end.

Thank you!

caofx0418 commented 11 months ago

Hi @caofx0418,

From the issue description, it appears that you are attempting to use the Image Generator Task in the C++ platform. However, please note that the Image Generator is exclusively available in the Android platform, and customisation is achievable in the Python platform, as explained in our documentation.

Could you kindly outline the specific steps you are following, making reference to the documentation? Additionally, if you are following the documentation, please confirm the Operating System, Android Studio version, Android SDK versions, and indicate whether you are able to run other examples based on the Android steps provided here.

This information will assist us in reproducing and gaining a better understanding of the issue on our end.

Thank you!

HI @kuaashish

thank you for your replay, I want to use in Android Platform, and integrate with my C++ project.

So my project is only depended by libmediapipe_tasks_vision_image_generator_jni.so and libimagegenerator_gpu.so.

I need to compile "libmediapipe_tasks_vision_image_generator_jni.so" standalone.

Mediapipe Vision: v0.10.5

Build Operating System/Android Studio version/Android SDK versions:
build in docker, and build docker from dockerfile in v0.10.5

build libmediapipe_tasks_vision_image_generator_jni.so command: bazel build -s -c opt --define MEDIAPIPE_DISABLE_OPENCV=1 --define EXCLUDE_OPENCV_SO_LIB=1 --strip always --config=android_arm64 mediapipe/tasks/java/com/google/mediapipe/tasks/vision/imagegenerator:libmediapipe_tasks_vision_image_generator_jni.so

khanhlvg commented 11 months ago

Can you elaborate why you need to use the C++ API but not the Java API via the prebuilt Maven target?

caofx0418 commented 11 months ago

Can you elaborate why you need to use the C++ API but not the Java API via the prebuilt Maven target?

Because my project is existing cpp opencv NDK project. So I want to integrate the new function with cpp interface to the existing c++ ndk code.

BraveEvidence commented 6 months ago

I am kind of facing similar issue while using kotlin