{"id":18456434,"url":"https://github.com/nicosnicolaou16/flutterandroidprojectandndk","last_synced_at":"2025-06-18T14:38:16.850Z","repository":{"id":215677066,"uuid":"736250601","full_name":"NicosNicolaou16/FlutterAndroidProjectAndNDK","owner":"NicosNicolaou16","description":"This project sets up the NDK (Native Development Kit) in Android for communication between an Android project and C/C++ code. In this example, the C/C++ code simply prints a text message to the Android application.","archived":false,"fork":false,"pushed_at":"2025-05-18T15:06:26.000Z","size":2760,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T16:23:02.697Z","etag":null,"topics":["android","c","cmake","dart","flutter","flutter-app","kotlin","kotlin-android","ndk","ndk-cmake"],"latest_commit_sha":null,"homepage":"https://medium.com/@nicosnicolaou/ndk-setup-on-android-flutter-android-project-1571d9a3f5cb","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/NicosNicolaou16.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-27T11:46:18.000Z","updated_at":"2025-05-18T15:06:30.000Z","dependencies_parsed_at":"2024-01-05T21:22:59.712Z","dependency_job_id":"417f977d-8e5b-4cbf-9859-360c02004733","html_url":"https://github.com/NicosNicolaou16/FlutterAndroidProjectAndNDK","commit_stats":null,"previous_names":["nicosnicolaou16/flutterandroidprojectandndk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NicosNicolaou16/FlutterAndroidProjectAndNDK","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FFlutterAndroidProjectAndNDK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FFlutterAndroidProjectAndNDK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FFlutterAndroidProjectAndNDK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FFlutterAndroidProjectAndNDK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NicosNicolaou16","download_url":"https://codeload.github.com/NicosNicolaou16/FlutterAndroidProjectAndNDK/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FFlutterAndroidProjectAndNDK/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260572328,"owners_count":23030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","c","cmake","dart","flutter","flutter-app","kotlin","kotlin-android","ndk","ndk-cmake"],"created_at":"2024-11-06T08:11:30.873Z","updated_at":"2025-06-18T14:38:11.837Z","avatar_url":"https://github.com/NicosNicolaou16.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flutter Android Project and NDK\n\nThis project sets up the NDK (Native Development Kit) in Android for communication between an\nAndroid project and C/C++ code. In this example, the C/C++ code simply prints a text message to the\nAndroid application. \u003cbr /\u003e\nFor communication between Android Native and Flutter, I used a channel (refer to the documentation\nfor more details). If you need an additional example of using channels, please check my repository\nfor more information: [ExampleChannelNativeAndroidWithCustomData](https://github.com/NicosNicolaou16/ExampleChannelNativeAndroidWithCustomData).\n\n\u003e [!IMPORTANT]\n\u003e NOTE: EXAMPLE FOR ANDROID ONLY. \u003cbr /\u003e\n\n# Setup - Steps\n\n- Install the latest NDK and CMake version from Android Studio SDK Manager from the SDK Tools\n  section.\n- Create the cpp package, add the CMake .txt and .cpp file. Some name below is base on .cpp file\n  name.\n\n```cmake\n# For more information about using CMake with Android Studio, read the\n# documentation: https://d.android.com/studio/projects/add-native-code.html\n\n# Sets the minimum version of CMake required to build the native library.\n\ncmake_minimum_required(VERSION 3.4.1)\n\n# Creates and names a library, sets it as either STATIC\n# or SHARED, and provides the relative paths to its source code.\n# You can define multiple libraries, and CMake builds them for you.\n# Gradle automatically packages shared libraries with your APK.\n\nadd_library( # Sets the name of the library.\n        message # based on .cpp file name\n\n        # Sets the library as a shared library.\n        SHARED\n\n        # Provides a relative path to your source file(s).\n        message.cpp) # based on .cpp file name\n\n# Searches for a specified prebuilt library and stores the path as a\n# variable. Because CMake includes system libraries in the search path by\n# default, you only need to specify the name of the public NDK library\n# you want to add. CMake verifies that the library exists before\n# completing its build.\n\nfind_library( # Sets the name of the path variable.\n        log-lib\n\n        # Specifies the name of the NDK library that\n        # you want CMake to locate.\n        log)\n\n# Specifies libraries CMake should link to your target library. You\n# can link multiple libraries, such as libraries you define in this\n# build script, prebuilt third-party libraries, or system libraries.\n\ntarget_link_libraries( # Specifies the target library.\n        message # based on .cpp file name\n\n        # Links the target library to the log library\n        # included in the NDK.\n        ${log-lib})\n```\n\n- Add the follow code in Gradle file.\n\n```Kotlin\nandroid {\n\n    //Other Gradle Code Here...\n\n    externalNativeBuild {\n        cmake {\n            path = file(\"src/main/cpp/CMakeLists.txt\")\n            version = \"3.31.5\"\n        }\n    }\n    ndkVersion = \"28.0.13004108\"\n\n    //Other Gradle Code Here...\n}\n```\n\n- Load the C/C++ file.\n\n```Kotlin\ncompanion object {\n    /**\n     * Load the C file\n     * */\n    init {\n        System.loadLibrary(\"message\")\n    }\n}\n```\n\n- Initialize the method(s) from .cpp file.\n\n```Kotlin\nprivate external fun message(): String \n```\n\n\u003e [!IMPORTANT]  \n\u003e Check my article :point_right: [NDK Setup on Android/Flutter Android Project - Medium](https://medium.com/@nicosnicolaou/ndk-setup-on-android-flutter-android-project-1571d9a3f5cb) :point_left: \u003cbr /\u003e\n\n\u003e [!IMPORTANT]  \n\u003e Similar project with (Kotlin Language) :point_right: [AndroidProjectAndNDK](https://github.com/NicosNicolaou16/AndroidProjectAndNDK) :point_left: \u003cbr /\u003e\n\n## Versioning\n\nFlutter SDK version: 3.27.3 \u003cbr /\u003e\nDart Version: 3.6.1 \u003cbr /\u003e\n\n# References/Tutorials Follow\n\nhttps://github.com/android/ndk-samples \u003cbr /\u003e\nhttps://developer.android.com/studio/projects/add-native-code \u003cbr /\u003e\nhttps://blog.mindorks.com/getting-started-with-android-ndk-android-tutorial/ \u003cbr /\u003e\nhttps://medium.com/@shreebhagwat94/flutter-platform-channel-46578d21e69 \u003cbr /\u003e\nhttps://blog.devgenius.io/use-flutter-screens-in-native-android-app-share-data-among-them-d97d670807a6 \u003cbr /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicosnicolaou16%2Fflutterandroidprojectandndk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicosnicolaou16%2Fflutterandroidprojectandndk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicosnicolaou16%2Fflutterandroidprojectandndk/lists"}