Skip to content

Commit b3e6e22

Browse files
committed
Include powersync_flutter_libs
1 parent b450ac3 commit b3e6e22

31 files changed

+1234
-1
lines changed

packages/powersync/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
sqlite_async: ^0.6.1
1414
sqlite3_flutter_libs: ^0.5.15
1515
powersync_flutter_libs:
16-
path: ../../../powersync_flutter_libs
16+
path: ../powersync_flutter_libs
1717
http: ^1.1.0
1818
uuid: ^4.2.0
1919
async: ^2.10.0
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
build/
30+
31+
*.so
32+
*.a
33+
*.dylib
34+
*.dll
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "54e66469a933b60ddf175f858f82eaeb97e48c8d"
8+
channel: "stable"
9+
10+
project_type: plugin_ffi
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
17+
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
18+
- platform: android
19+
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
20+
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
21+
- platform: ios
22+
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
23+
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
24+
- platform: linux
25+
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
26+
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
27+
- platform: macos
28+
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
29+
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
30+
- platform: windows
31+
create_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
32+
base_revision: 54e66469a933b60ddf175f858f82eaeb97e48c8d
33+
34+
# User provided section
35+
36+
# List of Local paths (relative to this file) that should be
37+
# ignored by the migrate tool.
38+
#
39+
# Files that are not part of the templates will be ignored by default.
40+
unmanaged_files:
41+
- 'lib/main.dart'
42+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* TODO: Describe initial release.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Add your license here.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# powersync_flutter_libs
2+
3+
### Flutter binaries for [Powersync](https://pub.dev/packages/powersync) please go there for documentation.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter
8+
[FFI plugin](https://docs.flutter.dev/development/platform-integration/c-interop),
9+
a specialized package that includes native code directly invoked with Dart FFI.
10+
11+
## Project structure
12+
13+
This template uses the following structure:
14+
15+
- `src`: Contains the native source code, and a CmakeFile.txt file for building
16+
that source code into a dynamic library.
17+
18+
- `lib`: Contains the Dart code that defines the API of the plugin, and which
19+
calls into the native code using `dart:ffi`.
20+
21+
- platform folders (`android`, `ios`, `windows`, etc.): Contains the build files
22+
for building and bundling the native code library with the platform application.
23+
24+
## Building and bundling native code
25+
26+
The `pubspec.yaml` specifies FFI plugins as follows:
27+
28+
```yaml
29+
plugin:
30+
platforms:
31+
some_platform:
32+
ffiPlugin: true
33+
```
34+
35+
This configuration invokes the native build for the various target platforms
36+
and bundles the binaries in Flutter applications using these FFI plugins.
37+
38+
This can be combined with dartPluginClass, such as when FFI is used for the
39+
implementation of one platform in a federated plugin:
40+
41+
```yaml
42+
plugin:
43+
implements: some_other_plugin
44+
platforms:
45+
some_platform:
46+
dartPluginClass: SomeClass
47+
ffiPlugin: true
48+
```
49+
50+
A plugin can have both FFI and method channels:
51+
52+
```yaml
53+
plugin:
54+
platforms:
55+
some_platform:
56+
pluginClass: SomeName
57+
ffiPlugin: true
58+
```
59+
60+
The native build systems that are invoked by FFI (and method channel) plugins are:
61+
62+
- For Android: Gradle, which invokes the Android NDK for native builds.
63+
- See the documentation in android/build.gradle.
64+
- For iOS and MacOS: Xcode, via CocoaPods.
65+
- See the documentation in ios/powersync_flutter_libs.podspec.
66+
- See the documentation in macos/powersync_flutter_libs.podspec.
67+
- For Linux and Windows: CMake.
68+
- See the documentation in linux/CMakeLists.txt.
69+
- See the documentation in windows/CMakeLists.txt.
70+
71+
## Binding to native code
72+
73+
To use the native code, bindings in Dart are needed.
74+
To avoid writing these by hand, they are generated from the header file
75+
(`src/powersync_flutter_libs.h`) by `package:ffigen`.
76+
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.
77+
78+
## Invoking native code
79+
80+
Very short-running native functions can be directly invoked from any isolate.
81+
For example, see `sum` in `lib/powersync_flutter_libs.dart`.
82+
83+
Longer-running functions should be invoked on a helper isolate to avoid
84+
dropping frames in Flutter applications.
85+
For example, see `sumAsync` in `lib/powersync_flutter_libs.dart`.
86+
87+
## Flutter help
88+
89+
For help getting started with Flutter, view our
90+
[online documentation](https://flutter.dev/docs), which offers tutorials,
91+
samples, guidance on mobile development, and a full API reference.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// The Android Gradle Plugin builds the native code with the Android NDK.
2+
3+
group 'com.example.powersync_flutter_libs'
4+
version '1.0'
5+
6+
buildscript {
7+
repositories {
8+
google()
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
// The Android Gradle Plugin knows how to build native code with the NDK.
14+
classpath 'com.android.tools.build:gradle:7.3.0'
15+
}
16+
}
17+
18+
rootProject.allprojects {
19+
repositories {
20+
google()
21+
mavenCentral()
22+
}
23+
}
24+
25+
apply plugin: 'com.android.library'
26+
27+
android {
28+
if (project.android.hasProperty("namespace")) {
29+
namespace 'com.example.powersync_flutter_libs'
30+
}
31+
32+
// Bumping the plugin compileSdk version requires all clients of this plugin
33+
// to bump the version in their app.
34+
compileSdk 34
35+
36+
// Use the NDK version
37+
// declared in /android/app/build.gradle file of the Flutter project.
38+
// Replace it with a version number if this plugin requires a specfic NDK version.
39+
// (e.g. ndkVersion "23.1.7779620")
40+
ndkVersion android.ndkVersion
41+
42+
// Invoke the shared CMake build with the Android Gradle Plugin.
43+
externalNativeBuild {
44+
cmake {
45+
path "../src/CMakeLists.txt"
46+
47+
// The default CMake version for the Android Gradle Plugin is 3.10.2.
48+
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
49+
//
50+
// The Flutter tooling requires that developers have CMake 3.10 or later
51+
// installed. You should not increase this version, as doing so will cause
52+
// the plugin to fail to compile for some customers of the plugin.
53+
// version "3.10.2"
54+
}
55+
}
56+
57+
compileOptions {
58+
sourceCompatibility JavaVersion.VERSION_1_8
59+
targetCompatibility JavaVersion.VERSION_1_8
60+
}
61+
62+
defaultConfig {
63+
minSdkVersion 19
64+
}
65+
}
66+
67+
dependencies {
68+
implementation 'co.powersync:powersync-sqlite-core:0.1.6'
69+
}
Binary file not shown.

0 commit comments

Comments
 (0)