Skip to content

Commit

Permalink
Merge pull request #783 from breez/flutter-ios-dynamic-linking
Browse files Browse the repository at this point in the history
Link bindings dynamically in iOS Flutter plugin
  • Loading branch information
roeierez authored Feb 13, 2024
2 parents 04c5b11 + c9b8f17 commit abc45d4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-all-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ jobs:
publish-flutter:
needs:
- setup
- build-language-bindings
if: ${{ needs.setup.outputs.flutter == 'true' }}
uses: ./.github/workflows/publish-flutter.yml
with:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/publish-flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ jobs:
cp ../breez-sdk/libs/sdk-flutter/pubspec.yaml .
cp ../breez-sdk/libs/sdk-flutter/pubspec.lock .
- uses: actions/download-artifact@v3
with:
name: bindings-swift
path: flutter/ios/bindings-swift/Sources/BreezSDK/

- name: Set package version
working-directory: flutter
run: |
sed -i.bak -e 's/version:.*/version: ${{ inputs.package-version }}/' pubspec.yaml
sed -i.bak -e "s/^version .*/version '${{ inputs.package-version }}'/" android/build.gradle
sed -i.bak -e "s/s.version = .*/s.version = '${{ inputs.package-version }}'/" ios/breez_sdk.podspec
sed -i.bak -e "s/^tag_version = .*/tag_version = '${{ inputs.package-version }}'/" ios/breez_sdk.podspec
rm pubspec.yaml.bak
rm android/build.gradle.bak
rm ios/breez_sdk.podspec.bak
Expand Down
25 changes: 20 additions & 5 deletions libs/sdk-flutter/ios/breez_sdk.podspec.production
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint breez_sdk.podspec` to validate before publishing.
tag_version = '0.2.15'
framework = 'breez_sdkFFI.xcframework'
lib_name = "breez-sdkFFI.#{tag_version}"
url = "https://github.com/breez/breez-sdk-swift/releases/download/#{tag_version}/#{framework}.zip"
frameworks_dir = 'bindings-swift'

`
if [ ! -d #{frameworks_dir}/#{framework} ]; then
mkdir -p #{frameworks_dir}
curl -L #{url} -o #{frameworks_dir}/#{lib_name}.zip
cd #{frameworks_dir}
unzip #{lib_name}.zip
rm -rf __MACOSX
rm #{lib_name}.zip
fi
`

Pod::Spec.new do |s|
s.name = 'breez_sdk'
s.version = '0.2.15'
s.version = "#{tag_version}"
s.summary = 'BreezSDK flutter plugin.'
s.description = <<-DESC
BreezSDK flutter plugin.
Expand All @@ -12,12 +27,12 @@ Pod::Spec.new do |s|
s.author = { 'Breez' => '[email protected]' }
s.source = { :git => "https://github.com/breez/breez-sdk-flutter.git", :tag => "#{s.version}" }
s.source_files = 'Classes/**/*'
s.on_demand_resources = { 'BreezSDK' => 'bindings-swift/Sources/BreezSDK/BreezSDK.swift' }
s.dependency 'Flutter'
s.platform = :ios, '11.0'
s.static_framework = true

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = {'STRIP_STYLE' => 'non-global', 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'
s.dependency "BreezSDK", "#{s.version}"
s.vendored_frameworks = "#{frameworks_dir}/#{framework}"
end
8 changes: 6 additions & 2 deletions libs/sdk-flutter/lib/native_toolkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'bridge_generated.dart';
BreezSdkCore? _breezSDK;

const _libName = "libbreez_sdk_bindings.so";
const _iosLibName = "breez_sdk";

class UnsupportedPlatform implements Exception {
UnsupportedPlatform(String s);
Expand All @@ -16,8 +17,11 @@ BreezSdkCore getNativeToolkit() {
// On Linux the lib needs to be in LD_LIBRARY_PATH or working directory
_breezSDK = BreezSdkCoreImpl(DynamicLibrary.open(_libName));
} else if (Platform.isIOS || Platform.isMacOS) {
// iOS and macOS are statically linked
_breezSDK = BreezSdkCoreImpl(DynamicLibrary.process());
try {
_breezSDK = BreezSdkCoreImpl(DynamicLibrary.open("$_iosLibName.framework/$_iosLibName"));
} catch (e) {
_breezSDK = BreezSdkCoreImpl(DynamicLibrary.process());
}
} else {
throw UnsupportedPlatform('${Platform.operatingSystem} is not yet supported!');
}
Expand Down
4 changes: 2 additions & 2 deletions libs/sdk-flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: breez_sdk
description: A new flutter plugin project.
description: Flutter bindings for the Breez SDK
repository: https://github.com/breez/breez-sdk-flutter
version: 0.2.15
publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit abc45d4

Please sign in to comment.