{"id":18456406,"url":"https://github.com/nicosnicolaou16/androidprojectandndk","last_synced_at":"2025-04-22T19:27:10.192Z","repository":{"id":215676945,"uuid":"736048424","full_name":"NicosNicolaou16/AndroidProjectAndNDK","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-02-07T20:29:44.000Z","size":141,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T14:58:29.059Z","etag":null,"topics":["android","c","cmake","cplusplus","cpp","jetpack-android","jetpack-compose","kotlin","kotlin-android","ndk","ndk-cmake"],"latest_commit_sha":null,"homepage":"https://medium.com/@nicosnicolaou/ndk-setup-on-android-flutter-android-project-1571d9a3f5cb","language":"Kotlin","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}},"created_at":"2023-12-26T20:52:38.000Z","updated_at":"2025-02-07T20:29:48.000Z","dependencies_parsed_at":"2024-01-05T21:22:26.249Z","dependency_job_id":"8697c364-4fc3-4f1e-aebc-8b02fd03fa11","html_url":"https://github.com/NicosNicolaou16/AndroidProjectAndNDK","commit_stats":null,"previous_names":["nicosnicolaou16/androidprojectandndk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FAndroidProjectAndNDK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FAndroidProjectAndNDK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FAndroidProjectAndNDK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicosNicolaou16%2FAndroidProjectAndNDK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NicosNicolaou16","download_url":"https://codeload.github.com/NicosNicolaou16/AndroidProjectAndNDK/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250307796,"owners_count":21409147,"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","cplusplus","cpp","jetpack-android","jetpack-compose","kotlin","kotlin-android","ndk","ndk-cmake"],"created_at":"2024-11-06T08:11:27.781Z","updated_at":"2025-04-22T19:27:10.169Z","avatar_url":"https://github.com/NicosNicolaou16.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Android Project and NDK (Kotlin)\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.\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 (Dart Language) :point_right: [FlutterAndroidProjectAndNDK](https://github.com/NicosNicolaou16/FlutterAndroidProjectAndNDK) :point_left: \u003cbr /\u003e\n\n## Versioning\n\nTarget SDK version: 35 \u003cbr /\u003e\nMinimum SDK version: 28 \u003cbr /\u003e\nKotlin version: 2.1.10 \u003cbr /\u003e\nGradle version: 8.8.0 \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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicosnicolaou16%2Fandroidprojectandndk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicosnicolaou16%2Fandroidprojectandndk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicosnicolaou16%2Fandroidprojectandndk/lists"}