Failed to load dynamic library and got bad ELF magic error in flutter

170 Views Asked by At

I am trying to use the ffi package to be able to use c++ to use mediapipe. To get started I want to execute a simple printf function.

#include <stdio.h>

void produce_landmarks()
{
    printf("Hi at least that works.");
}

I compiled the shared library with: g++ -shared -o produce_landmarks.so -fPIC produce_landmarks.cpp

Then I put this .so file into the following folder structure: android/app/app/src/jniLibs/arm64-v8a/produce_landmarks.so

Then I also added following statements to my AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Now I am trying:

final dynamic = DynamicLibrary.open('produce_landmarks.so');

final void Function() produce_landmarks = dynamic.lookupFunction<Void Function(), void Function()>('produce_landmarks');
        produce_landmarks();

When I tried to use a different path I always got an error that the path/file could not be found. Now at least I don't get this error but I got this instead:

Invalid argument(s): Failed to load dynamic library 'produce_landmarks.so': dlopen failed: "/data/app/~~WBEv1F4KjMIeZUnNQYr1XQ==/com.example.mm_gym_tracker-HNS3OELpzcrnR0-wbVZFow==/lib/arm64/produce_landmarks.so" has bad ELF magic: 4d5a9000

I want my printf visible in my debug output without any errors.

0

There are 0 best solutions below