explaingit

android/ndk-samples

10,508C++Audience · developerComplexity · 3/5LicenseSetup · moderate

TLDR

Official Google sample apps showing how to use the Android NDK to write C or C++ code inside Android apps, useful for games, high-performance computing, and reusing native libraries.

Mindmap

mindmap
  root((repo))
    What it Does
      Demo NDK features
      Show C++ in Android
      Reference code only
    Tech Used
      Android NDK
      CMake build system
      Gradle tooling
    Topics
      Graphics rendering
      Native library linking
      Function registration
    Audience
      Android developers
      Game developers
      C++ library authors
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Open a specific sample in Android Studio to see a minimal working example of a single NDK feature like audio or graphics before adding it to your own app.

USE CASE 2

Build the samples from the command line with Gradle to understand how CMake integrates with the Android build system.

USE CASE 3

Study the recommended C function registration pattern the samples use consistently to learn the correct way to call C code from Java.

USE CASE 4

Use the version script examples to learn how to control which functions in your C++ library are exposed, reducing library size and improving load speed.

Tech stack

C++JavaKotlinAndroid NDKCMakeGradle

Getting it running

Difficulty · moderate Time to first run · 30min

Requires installing a specific CMake version via the Android Studio SDK Manager before the C++ samples will build.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

This repository contains sample Android apps that demonstrate how to use the Android NDK, which is a set of tools that lets you write parts of an Android app in C or C++ rather than Java or Kotlin. Native code is useful in situations where you need high performance, want to reuse existing C or C++ libraries, or are building a game that renders its own graphics directly without using the standard Android interface components. Each sample is a small focused app that shows one specific NDK feature or API in isolation. The samples are intentionally simplified to keep the demonstrations clear, which also means they cut some corners that a real production app would not. The README is direct about this: these samples are reference material and not a template to copy as a starting point for a new project. For that, the Android Studio new project wizard has templates designed specifically for native apps. To build and run the samples you open the whole project in Android Studio and select whichever sample you want from the toolbar. You can also build from the command line using the gradle build tool. The only manual step is installing a specific version of CMake, the build system used to compile the C++ code, through the Android Studio SDK Manager. The repository also documents a few practices used consistently across the samples that are worth understanding. One is a preferred way of registering C functions so that Android can call them from Java code. Another is the use of version scripts, which are configuration files that control which functions in a compiled C++ library are visible from outside it. Using them produces smaller and faster libraries. The project is maintained by Google's Android team and is open source under the Apache 2.0 license.

Copy-paste prompts

Prompt 1
I want to write a native C++ audio processing function and call it from my Android Java code. Walk me through the NDK setup and show me the function registration pattern used in the ndk-samples repo.
Prompt 2
Show me how to add a CMakeLists.txt file to my Android Studio project to compile a C++ file using the same approach as the android/ndk-samples repo.
Prompt 3
I need to build the ndk-samples project from the command line using Gradle. Give me the exact commands to install CMake through the Android SDK Manager and then build a specific sample.
Prompt 4
What is a version script in C++ NDK development and why do the ndk-samples use them? Explain it simply and show an example based on the repo's approach.
Prompt 5
I want to render custom graphics in my Android game without using standard Android UI components. Which ndk-samples sample should I look at first and what does it demonstrate?
Open on GitHub → Explain another repo

← android on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.