Skip to content

crashes when calling c++ in arm android #15006

@yyccR

Description

@yyccR
System information (version)
  • OpenVINO => 2022.3.0
  • Operating System / Platform => Android(arm64)
  • Compiler => Visual Studio 2017
Detailed description

I was going to use openvino in flutter by calling c++ instead of using the Java api, but it crashed when calling c++ to initialize the model, here is the error msg:
Abort message: 'terminating with uncaught exception of type ov::Exception: Can't get absolute file path for [/data/app/com.test.test-YcefHGmNSq6Rurhx-jV-xQ==/base.apk!/lib/arm64-v8a/libopenvino.so], err = No such file or directory'

here is the c++ code:

#include <iostream>
#include "memory"
#include "openvino/runtime/runtime.hpp"

int initOpenvinoModel(std::string &plugin_xml, std::string &xml_model_path, std::string &bin_model_path) {

    std::shared_ptr<ov::Core> core = std::make_shared<ov::Core>(plugin_xml);
    // std::shared_ptr<ov::Model> model = core.read_model(xml_model_path, bin_model_path);
    // core.compile_model(model, "CPU");
    return 0;
}

extern "C" __attribute__((visibility("default"))) __attribute__((used))
int initOpenvinoModel_c(char* plugin_xml_path, char* xml_model_path, char* bin_model_path) {
    std::string plugin_xml_path_s(plugin_xml_path);
    std::string xml_model_path_s(xml_model_path);
    std::string bin_model_path_s(bin_model_path);
    return initOpenvinoModel(plugin_xml_path_s, xml_model_path_s, bin_model_path_s);
}

and I have build the openvino with arm cpu plugin, below is the shared library and plugins.xml:

libopenvino.so
libopenvino_arm_cpu_plugin.so
libopenvino_auto_batch_plugin.so
libopenvino_auto_plugin.so
libopenvino_hetero_plugin.so
<ie>
    <plugins>
        <plugin name="AUTO" location="libopenvino_auto_plugin.so">
        </plugin>
        <plugin name="BATCH" location="libopenvino_auto_batch_plugin.so">
        </plugin>
        <plugin name="CPU" location="libopenvino_arm_cpu_plugin.so">
        </plugin>
        <plugin name="HETERO" location="libopenvino_hetero_plugin.so">
        </plugin>
        <plugin name="MULTI" location="libopenvino_auto_plugin.so">
        </plugin>
    </plugins>
</ie>

I have linked the libopenvino.so in the project and include all the header files, this is my CMakeLists.txt

cmake_minimum_required(VERSION 3.17.0)
project(test)
set(CMAKE_CXX_STANDARD 17)

include_directories(${CMAKE_CURRENT_LIST_DIR}/libs/openvino-2022.3.0/include)

set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/libs/opencv-mobile-4.5.4-android/sdk/native/jni)
find_package(OpenCV REQUIRED core imgproc highgui)

add_library(openvino SHARED IMPORTED)
set_target_properties(openvino PROPERTIES IMPORTED_LOCATION
        ${CMAKE_CURRENT_LIST_DIR}/libs/openvino-2022.3.0/${ANDROID_ABI}/libopenvino.so)

aux_source_directory(${CMAKE_SOURCE_DIR}/openvino_cpp openvino_src_lists)
add_library(test SHARED ${openvino_src_lists})
target_link_libraries(test ${OpenCV_LIBS})
target_link_libraries(test openvino)

And I've put all the plugin shared libraries in the same directory as libopevino.so。

I also put plugins.xml, openvino_model.xml, openvino_model.bin in the assert directory and copy these three files to the android system when I start the application so that c++ programs can read them.

The error below

Abort message: 'terminating with uncaught exception of type ov::Exception: Can't get absolute file path for [/data/app/com.test.test-YcefHGmNSq6Rurhx-jV-xQ==/base.apk!/lib/arm64-v8a/libopenvino.so], err = No such file or directory'

seems that openvino c++ wants to find the libopenvino library directory and get the plugin shared library, but cannot access it when android is not root

So I've put all the plugin.so in the asset directory, and change the plugins.xml into :

<ie>
    <plugins>
        <plugin name="AUTO" location="/data/user/0/com.test.test/app_flutter/libopenvino_auto_plugin.so">
        </plugin>
        <plugin name="BATCH" location="/data/user/0/com.test.test/app_flutter/libopenvino_auto_batch_plugin.so">
        </plugin>
        <plugin name="CPU" location="/data/user/0/com.test.test/app_flutter/libopenvino_arm_cpu_plugin.so">
        </plugin>
        <plugin name="HETERO" location="/data/user/0/com.test.test/app_flutter/libopenvino_hetero_plugin.so">
        </plugin>
        <plugin name="MULTI" location="/data/user/0/com.test.test/app_flutter/libopenvino_auto_plugin.so">
        </plugin>
    </plugins>
</ie>

The location in plugins.xml is the path to the android system file, which can be read by c++ programs, and is the target copy path to the asset file。

After trying, I still get the same error message.

please let me know if you have a solution.

Thank you so much.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions