{"id":50527559,"url":"https://github.com/peter-sidra/flutter_ffi_template","last_synced_at":"2026-06-03T09:04:03.974Z","repository":{"id":220882511,"uuid":"390060983","full_name":"peter-sidra/flutter_ffi_template","owner":"peter-sidra","description":"A template for developing flutter apps using native C/C++ code.","archived":false,"fork":false,"pushed_at":"2021-08-01T19:45:57.000Z","size":88,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-02-04T23:46:40.515Z","etag":null,"topics":["android","cpp","dart","ffi","flutter","vcpkg"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peter-sidra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-07-27T16:54:17.000Z","updated_at":"2024-02-04T23:46:42.019Z","dependencies_parsed_at":"2024-02-04T23:56:47.863Z","dependency_job_id":null,"html_url":"https://github.com/peter-sidra/flutter_ffi_template","commit_stats":null,"previous_names":["peter-sidra/flutter_ffi_template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peter-sidra/flutter_ffi_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-sidra%2Fflutter_ffi_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-sidra%2Fflutter_ffi_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-sidra%2Fflutter_ffi_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-sidra%2Fflutter_ffi_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter-sidra","download_url":"https://codeload.github.com/peter-sidra/flutter_ffi_template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-sidra%2Fflutter_ffi_template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33856288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-03T02:00:06.370Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cpp","dart","ffi","flutter","vcpkg"],"created_at":"2026-06-03T09:04:02.427Z","updated_at":"2026-06-03T09:04:03.963Z","avatar_url":"https://github.com/peter-sidra.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flutter FFI + VCPKG template\n\nA template for developing flutter apps using native C/C++ code. This template uses VCPKG and CMake to manage the native dependencies in a cross platform manner. The template currently only implements Android and Windows platforms, but can be easily extended for other platforms.\n\n## Prerequisites\n- [Ninja](https://github.com/ninja-build/ninja)\n- [CMake](https://github.com/Kitware/CMake)\n- [VCPKG](https://github.com/microsoft/vcpkg)\n- Set the environment variable ```VCPKG_DIR``` to the VCPKG installation directory.\n- Set the environment variable ```ANDROID_NDK_HOME``` to the NDK installation directory.\n\n## Project Structure\nThe native code is located in [/ffi](ffi). The [CMakeLists.txt](ffi/CMakeLists.txt) build script is invoked automatically by gradle for android and CMake for Windows (and linux).\n\n##### Android\n[android/app/build.gradle](android/app/build.gradle)\n```groovy\nexternalNativeBuild {\n    cmake {\n        path \"../../ffi/CMakeLists.txt\"\n        version \"3.18.0+\"\n    }\n}\n```\n\n##### Windows\nA custom post build command was added to [windows/runner/CMakeLists.txt](windows/runner/CMakeLists.txt) to configure and build the native code\n```cmake\nadd_custom_command(TARGET ${BINARY_NAME} POST_BUILD\n                  COMMAND dart ${CMAKE_CURRENT_SOURCE_DIR}/../../ffi/build.dart \"Windows\"\n                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../ffi)\n```\nThis command calls the dart script [ffi/build.dart](ffi/build.dart) which in turn configures and builds the native library according to [ffi/CMakeLists.txt](ffi/CMakeLists.txt).\n\n[ffi/build.dart](ffi/build.dart) accepts one argument; the target platform name (ex. \"Windows\"). It is designed to allow new platforms to easily build the native library while managing the platform differences in [ffi/CMakeLists.txt](ffi/CMakeLists.txt).\n\n##### The native library\nThe binary of the shared native library is built into ```ffi/build/${PlatformName}/${BuildType}``` where \\${PlatformName} is the platform name (ex. \"Windows\") and \\${BuildType} is the target ```CMAKE_BUILD_TYPE```\n\n## Usage Instructions\nTo add new native code, add your C\\C++ source files to [ffi/src](ffi/src) and edit [ffi/CMakeLists.txt](ffi/CMakeLists.txt) to reflect the changes to your source code, then make sure to edit the ffigen section in the [pubspec.yaml](pubspec.yaml)\n```yaml\nffigen:\n  name: \"GeneratedNativeLib\"\n  description: \"ffigen generated bindings to native lib\"\n  output: \"lib/native_lib/generated_native_lib.dart\"\n  headers:\n    entry-points:\n      - \"ffi/src/native_lib.h\"\n    include-directives:\n      - \"**native_lib.h\"\n```\nthen rerun ffigen to regenerate the dart bindings ```flutter pub run ffigen```\n\n## Tips\nThe native CMake project is configured to produce the compilation database file ```compile_commands.json``` in the ```ffi/build``` directory. You could point your vscode's C++ extension (I highly recommend clangd) to this file to provide intellisense while editing the native source code directly from vscode.  \nI provided a vscode task \"configure windows\" which you can use to regenerate the ```compile_commands.json``` after you make changes to [ffi/CMakeLists.txt](ffi/CMakeLists.txt). \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-sidra%2Fflutter_ffi_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter-sidra%2Fflutter_ffi_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-sidra%2Fflutter_ffi_template/lists"}