Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto setup #66

Merged
merged 9 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .github/workflows/build_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: build examples

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build-windows:
name: build-windows
runs-on: windows-latest

steps:
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: build
run: |
cd example
flutter build windows
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi
build-ubuntu:
name: build-ubuntu
runs-on: ubuntu-latest

steps:
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: setup
run: |
sudo apt-get update
sudo apt-get install -y curl git wget python3 unzip build-essential \
libgtk-3-dev ffmpeg libavcodec-dev \
cmake ninja-build nasm libavformat-dev libavutil-dev \
libswscale-dev libgflags-dev \
libjpeg-dev libpng-dev libtiff-dev python3-pip
- name: build
run: |
cd example
flutter build linux
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi
build-macos:
name: build-macos
runs-on: macos-13
steps:
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: build
run: |
cd example
flutter build macos
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi
flutter build ios --release --no-codesign
build-macos-arm:
name: build-macos-arm
runs-on: macos-14
steps:
- uses: subosito/flutter-action@v2
with:
# flutter-version: '3.16.9'
channel: "stable"
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: build
run: |
cd example
flutter build macos
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi
flutter build ios --release --no-codesign
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ OpenCV Bindings for Dart Language.
</p>

> [!IMPORTANT]
> Please use v0.3.0 and later version, usage:
> Please use `v0.3.0` and later version
>
> For `v1.0.5` and later, setup is no longer needed, the prebuilt libs will be downloaded from releases
> automatically, some notes:
>
> 1. iOS: default target architecture is `arm64`, if you need to run on `x64`(ios simulator), please
> set `OPENCV_DART_ARCH` to `x64`, e.g., `export OPENCV_DART_ARCH=x64`
> 2. Android: all supported ABIs (`x86_64` `arm64-v8a` `armeabi-v7a`) will be downloaded, if you want
> to reduce the app size, please add `--split-per-abi` to the `flutter build` command, e.g., `flutter build apk --release --target-platform android-arm64,android-x64 --split-per-abi`, otherwise, all `.so` will
> be packaged to app.
>
> For `v1.0.4` and below, make sure run the following setup commands before running your app:
>
> 1. `flutter pub add opencv_dart` or `dart pub add opencv_dart`
> 2. `dart run opencv_dart:setup <platform> --arch <arch>`
Expand Down Expand Up @@ -148,7 +159,7 @@ void main() {

#### Flutter

see [example](https://github.com/rainyl/opencv_dart/tree/native-assets/example)
see [example](https://github.com/rainyl/opencv_dart/tree/main/example)

More examples are on the way...

Expand Down
44 changes: 39 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// The Android Gradle Plugin builds the native code with the Android NDK.

group 'dev.rainyl.opencv_dart'
version '1.0'

Expand Down Expand Up @@ -33,9 +31,8 @@ android {
// to bump the version in their app.
compileSdk 33

// Use the NDK version
// declared in /android/app/build.gradle file of the Flutter project.
// Replace it with a version number if this plugin requires a specfic NDK version.
// Use the NDK version declared in /android/app/build.gradle file of the Flutter project.
// Replace it with a version number if this plugin requires a specific NDK version.
// (e.g. ndkVersion "23.1.7779620")
ndkVersion android.ndkVersion

Expand Down Expand Up @@ -63,3 +60,40 @@ android {
minSdkVersion 19
}
}

// 'dart' and 'dart.bat' both exists on windwos, the former is a bash script and won't work
// correctly on windows, so use `dart.bat`
def dartCmd = "dart"
def currentOS = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem
if(currentOS.isWindows()){
dartCmd = "dart.bat"
}

task runOpenCVSetup(type: Exec) {
// Set working directory to the parent directory of the root directory
workingDir rootDir.parentFile
commandLine dartCmd, 'run', 'opencv_dart:setup', 'android', '--arch', 'x86_64'
doFirst {
println "Running OpenCV setup for x86_64 in ${workingDir}"
}
}

task runOpenCVSetupArm64(type: Exec) {
// Set working directory to the parent directory of the root directory
workingDir rootDir.parentFile
commandLine dartCmd, 'run', 'opencv_dart:setup', 'android', '--arch', 'arm64-v8a'
doFirst {
println "Running OpenCV setup for arm64-v8a in ${workingDir}"
}
}

task runOpenCVSetupArmeabi(type: Exec) {
// Set working directory to the parent directory of the root directory
workingDir rootDir.parentFile
commandLine dartCmd, 'run', 'opencv_dart:setup', 'android', '--arch', 'armeabi-v7a'
doFirst {
println "Running OpenCV setup for armeabi-v7a in ${workingDir}"
}
}

preBuild.dependsOn runOpenCVSetup, runOpenCVSetupArm64, runOpenCVSetupArmeabi
12 changes: 12 additions & 0 deletions bin/setup_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ abstract class BaseSetupCommand extends Command {
if (!Directory(extractPath).existsSync()) {
Directory(extractPath).createSync(recursive: true);
}
// Check if libs already existed, avoid double-extract
if (Directory(extractPath)
.listSync()
.map((e) =>
e.path.endsWith(".so") ||
e.path.endsWith(".dll") ||
e.path.endsWith(".dylib") ||
e.path.endsWith(".framework"))
.any((e) => e)) {
print("Libs already exists in $extractPath, Skipping...");
return;
}
print("Extracting to $extractPath");
final tarBytes = GZipDecoder().decodeBytes(saveFile.readAsBytesSync());
final archive = TarDecoder().decodeBytes(tarBytes);
Expand Down
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
28 changes: 28 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PODS:
- Flutter (1.0.0)
- image_picker_ios (0.0.1):
- Flutter
- opencv_dart (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- opencv_dart (from `.symlinks/plugins/opencv_dart/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
opencv_dart:
:path: ".symlinks/plugins/opencv_dart/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
opencv_dart: 818b078a7168d455a7b84e1b1a0f444835ad666b

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

COCOAPODS: 1.15.2
Loading