{"id":30710767,"url":"https://github.com/helmssyss/basic-dart-ffi-example","last_synced_at":"2026-05-01T21:35:23.108Z","repository":{"id":312462742,"uuid":"1047585686","full_name":"Helmssyss/Basic-Dart-ffi-Example","owner":"Helmssyss","description":"Calling from function in C for Android Application","archived":false,"fork":false,"pushed_at":"2025-08-30T19:07:54.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-30T20:35:30.422Z","etag":null,"topics":["cpp","dart","ffi-bindings","flutter","flutter-examples"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Helmssyss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-30T18:43:56.000Z","updated_at":"2025-08-30T19:13:04.000Z","dependencies_parsed_at":"2025-08-30T20:46:29.148Z","dependency_job_id":null,"html_url":"https://github.com/Helmssyss/Basic-Dart-ffi-Example","commit_stats":null,"previous_names":["helmssyss/basic-dart-ffi-example"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Helmssyss/Basic-Dart-ffi-Example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Helmssyss%2FBasic-Dart-ffi-Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Helmssyss%2FBasic-Dart-ffi-Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Helmssyss%2FBasic-Dart-ffi-Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Helmssyss%2FBasic-Dart-ffi-Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Helmssyss","download_url":"https://codeload.github.com/Helmssyss/Basic-Dart-ffi-Example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Helmssyss%2FBasic-Dart-ffi-Example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32513961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["cpp","dart","ffi-bindings","flutter","flutter-examples"],"created_at":"2025-09-03T01:06:40.262Z","updated_at":"2026-05-01T21:35:23.072Z","avatar_url":"https://github.com/Helmssyss.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Getting Started\r\n\r\nEN\r\n\r\n1 - Create a CMakeLists.txt file under the Android folder. Write the name you want for it to be compiled as a dynamically shared file, then specify it with the `SHARED` key. Next, add the .cpp code you want to compile: `add_library(hello SHARED ../lib/hello.cpp)`. Since I wanted to use the cpp code in the same location as the dart files, I selected hello.cpp by specifying the path to the lib folder.\r\n\r\n2 - Go to android/app/build.gradle, and add the following line so that it matches the minimum version you specified in CMakeLists.txt (`cmake_minimum_required(VERSION 3.22.1)`):\r\n```gradle\r\nandroid{\r\n    namespace = \"...\"\r\n    compileSdk = ...\r\n    ndkVersion = ...\r\n    compileOptions{...}\r\n    kotlinOptions{...}\r\n    defaultConfig {...}\r\n\r\n//add new line\r\n    externalNativeBuild{\r\n        cmake{\r\n            path file(\"../CMakeLists.txt\")\r\n            version \"3.22.1\"\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n3 - If you are writing in C++, you must wrap your functions with `extern \"C\"` and then add the `__attribute__((visibility(“default”))) __attribute__((used))` flags. We must add these so that they can be used when compiled as a dynamic shared file (.so) for Android on the Dart FFI side. If you are writing in C, you only need to add the `__attribute__((visibility(“default”))) __attribute__((used))` flags. You can then run the project from main.dart.\r\n\r\n---------------\r\n\r\nTR\r\n\r\n1 - Android klasörü altında CMakeLists.txt dosyası oluşturun içeriğini dinamik paylaşılacak dosya olarak derlenmesi için istediğiniz ismi yazın ardından SHARED anahtarı ile belirtin daha sonra hangi .cpp kodunu derleyecekseniz onu ekleyin `add_library(hello SHARED ../lib/hello.cpp)`. Ben cpp kodunu dart dosyaları ile aynı konumda kullanmak istediğimden lib klasörünün yolunu vererek hello.cpp'yi seçtim.\r\n\r\n2 - `android/app/build.gradle` içerisine girin, CMakeLists.txt içerisinde belirttiğiniz minimum sürüm ile(`cmake_minimum_required(VERSION 3.22.1)`) aynı olacak şekilde aşağıdaki eklemeyi yapın\r\n```gradle\r\nandroid{\r\n    namespace = \"...\"\r\n    compileSdk = ...\r\n    ndkVersion = ...\r\n    compileOptions{...}\r\n    kotlinOptions{...}\r\n    defaultConfig {...}\r\n\r\n// bu satırı ekle\r\n    externalNativeBuild{\r\n        cmake{\r\n            path file(\"../CMakeLists.txt\")\r\n            version \"3.22.1\"\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n3 - Eğer C++ yazacaksanız fonksiyonlarınızı `extern \"C\"` ile sarmalamanız gerekir daha sonra `__attribute__((visibility(\"default\"))) __attribute__((used))` bayraklarını eklemelisiniz. Bu dart ffi tarafında Android için .so olarak dinamik paylaşılabilir dosya halinde derlendiğinde kullanılmak için bunları eklemek zorundayız. C ile yazacaksanız sadece `__attribute__((visibility(\"default\"))) __attribute__((used))` bayraklarını eklemeniz yeterli olacak. Daha sonra projeyi `main.dart`'tan çalıştırabilirsiniz.\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelmssyss%2Fbasic-dart-ffi-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelmssyss%2Fbasic-dart-ffi-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelmssyss%2Fbasic-dart-ffi-example/lists"}