Repository: flutter
Issue: Engine iOS unit tests do not run on a real device
Labels: a: tests,platform-ios,engine,P2,team-ios,triaged-ios

iOS engine device tests pass on a simulator, but fail on a real device.

### Steps to reproduce
1. Build `ios_debug_unopt` and `ios_test_flutter`
```
$  ./flutter/tools/gn --no-goma --unoptimized --ios && ninja -C out/ios_debug_unopt ios_test_flutter
```
2. Open in Xcode
```
$ open flutter/testing/ios/IosUnitTests/IosUnitTests.xcodeproj
```
3. Replace contents of [FlutterEngineConfig.xcconfig](https://github.com/flutter/engine/blob/138c91c614d742c52aa5432b4cb921f0ff9fdee2/testing/ios/IosUnitTests/Tests/FlutterEngineConfig.xcconfig)
```
FLUTTER_ENGINE=ios_debug_unopt
```
4. Set signing team in both targets, run unit tests on real (not simulator) iPhone, see it crash:
```
2021-08-04 17:16:10.060629-0700 IosUnitTests[5916:8586338] Failed to load test bundle from file:///private/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/: Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests): Library not loaded: @rpath/Frameworks/libocmock_shared.dylib
  Referenced from: /var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests
  Reason: image not found" UserInfo={NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests, NSDebugDescription=dlopen_preflight(/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests): Library not loaded: @rpath/Frameworks/libocmock_shared.dylib
  Referenced from: /var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests
  Reason: image not found, NSBundlePath=/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest, NSLocalizedDescription=The bundle “IosUnitTestsTests” couldn’t be loaded because it is damaged or missing necessary resources.}
2021-08-04 17:16:11.006344-0700 IosUnitTests[5916:8586338] The bundle “IosUnitTestsTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2021-08-04 17:16:11.006578-0700 IosUnitTests[5916:8586338] (dlopen_preflight(/var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests): Library not loaded: @rpath/Frameworks/libocmock_shared.dylib
  Referenced from: /var/containers/Bundle/Application/26CD81D5-0183-43CD-802D-1F5278BABB72/IosUnitTests.app/PlugIns/IosUnitTestsTests.xctest/IosUnitTestsTests
  Reason: image not found)
```
The same tests pass on a simulator.

A few problems here:
1. The dylibs aren't actually being embedded in the app.  However, the same problem persists when I fix that.
```
xcode_frameworks_dir="${TARGET_BUILD_DIR}/${PlugIns/IosUnitTestsTests.xctest/Frameworks/}"
```
should be:
```
xcode_frameworks_dir="${TARGET_BUILD_DIR}/${PLUGINS_FOLDER_PATH}/IosUnitTestsTests.xctest/Frameworks/"
```

2. When I set `DYLD_PRINT_LIBRARIES=1` in the scheme environment variables I can see that the dylib still doesn't load, same crash.
3. dylibs aren't supported on iOS and therefore don't load. "Dynamic libraries outside of a framework bundle, which typically have the file extension .dylib, are not supported on iOS, watchOS, or tvOS, except for the system Swift libraries provided by Xcode."
https://developer.apple.com/library/archive/technotes/tn2435/_index.html

`libocmock_shared.dylib` and `libios_test_flutter.dylib` instead should be generated as framework bundles.