Repository: flutter
Issue: Invalid argument(s): Failed to load dynamic library (dlopen failed: library "/shared_library/lib.so" not found)
Labels: engine,dependency: dart,P2,team-engine,triaged-engine

Im trying to call a C library using ffi and I can't open the .so file from the required folder

main:

```dart
import 'package:flutter/material.dart';
import 'package:flutter_app_demo/aboutPage.dart';
import 'package:flutter_app_demo/helpPage.dart';
import 'package:flutter_app_demo/reportPage.dart';
import 'package:flutter_app_demo/Resources.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_app_demo/Widgets.dart';
import 'package:flutter_app_demo/app.dart';

Struct Struct;
ValueStruct valueStruct;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
      routes: {
        Routes.helpPage: (BuildContext context) => HelpPage(),
        Routes.aboutPage: (BuildContext context) => AboutPage(),
        Routes.reportPage: (BuildContext context) => ReportPage(),
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  MyHomePageState createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: <Widget> [
          PopupMenuButton<String>(
            onSelected: choiceSelected,
            itemBuilder: (BuildContext context) {
              return Constants.choices.map((String choice) {
                return PopupMenuItem <String>(
                  value: choice,
                  child: Text(choice),
                );
              }).toList();
            },
          )
        ],
      ),
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              padding: EdgeInsets.only(top:10),
              child: Stack(
                alignment: Alignment.topLeft,
                children: [
                  MultivuLogo(),
                ],
              ),
            ),
            Row(
              children: [
                Text(main()),
              ],
            ),
          ]
        ),
        ),
      bottomNavigationBar: BottomBar()// This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  void choiceSelected(String choice) {
    switch(choice) {
      case Constants.Report:
        Navigator.pushNamed(context, Routes.reportPage);
        break;
      case Constants.About:
        Navigator.pushNamed(context, Routes.aboutPage);
        break;
      case Constants.Help:
        Navigator.pushNamed(context, Routes.helpPage);
        break;
    }
  }

  func() {
    Navigator.popUntil(context, ModalRoute.withName(Routes.homePage));
    print("Returned to home");
  }

  openWebsite() async {
    const url = urls.multivuWebsite;
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }
}
```

app:
```dart
import 'dart:io' show Directory, Platform;
import 'dart:ffi';
import 'package:path/path.dart' as path;
import 'package:ffi/ffi.dart';

Allocator allocator;
int byte = 8;
Utf8 utf8 = new Utf8();

 // value struct
class ValueStruct extends Struct {

  @Double()
  double retval;

  factory ValueStruct.allocate(double retval) =>
      allocator.allocate<ValueStruct>(byte * 8).ref
        ..retval = retval;
}

// struct
class Struct extends Struct {

  Pointer<Utf8> message;

  Pointer<ValueStruct> valstruct;

  factory Struct.allocate(Pointer<Utf8> message, Pointer<ValueStruct> valstruct) =>
      allocator.allocate<Struct>(byte * 8).ref
        ..message = message
        ..valstruct;
}

// call
typedef call_func = Pointer<Utf8> Function();

// Value Struct
typedef create_value_struct_func = Pointer<ValueStruct> Function(
    Double retval);
typedef CreateValueStruct = Pointer<ValueStruct> Function(
    double retval);

// Struct
typedef create_struct_func = Pointer<Struct> Function(
    Pointer<Utf8> message, Double retval);
typedef CreateStruct = Pointer<Struct> Function(
    Pointer<Utf8> message, double retval);

main() {

    // Open the shared library
    var libraryPath =
    path.join(Directory.current.path, 'shared_library', 'lib.so');
    if (Platform.isMacOS)
      libraryPath = path.join(
          Directory.current.path, 'shared_library', 'lib.dylib');
    if (Platform.isWindows)
      libraryPath = path.join(
          Directory.current.path, 'shared_library', 'Debug', 'file.dll');
    final dylib = DynamicLibrary.open(libraryPath);

    // call
    final _CallPointer =
    dylib.lookup<NativeFunction<call_func>>('call');
    final Call = _CallPointer.asFunction<call_func>();
    final callPointer = Call();
    final call = callPointer.toDartString();
    print('$call');

    // value struct
    final createValueStructPointer =
    dylib.lookup<NativeFunction<create_value_struct_func>>('create_value_struct');
    final createValueStruct =
    createValueStructPointer.asFunction<CreateValueStruct>();
    final valueStructPointer = createValueStruct(8.8);
    final valueStruct = valueStructPointer.ref;
    print('Return Value: ${valueStruct.retval}');

    // struct
    final createStructPointer =
    dylib.lookup<NativeFunction<create_struct_func>>('create_struct');
    final createStruct = createStructPointer.asFunction<CreateStruct>();
    final StructPointer = createStruct(callPointer, 88.88);
    final Struct = StructPointer.ref;
    final Message = Struct.message.toDartString(); //Utf8 has no such method
    final ValueStruct = Struct.valstruct.ref;
    print(
        'returned message $Message and value ${ValueStruct.retval}');

}
```

build.gradle

```dart
buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
```

cmakelist

```dart
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
project(shared_library VERSION 1.0.0 LANGUAGES C)
add_library(shared_library SHARED file.c file.def)
add_executable(test file.c)

set_target_properties(shared_library PROPERTIES
    PUBLIC_HEADER file.h
    VERSION ${PROJECT_VERSION}
    SOVERSION 1
    OUTPUT_NAME "file"
    XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "MacOS_ID"
)

```