Skip to main content

Overview

Android provides several native APIs that are specific to the Android platform. These APIs allow you to interact with Android system services, manage app resources, and integrate with the Android runtime.
All Android-specific APIs require linking against their respective libraries. Add them to your build configuration (CMake or ndk-build).

Native Activity

Native Activity allows you to create Android apps entirely in native code without writing Java/Kotlin code.

Key features

Library
Static helper library that simplifies NativeActivity lifecycle management. Recommended for all NativeActivity applications.

API reference

struct
Main application structure containing activity state, window, input queue, and callbacks.
ANativeActivity*
Pointer to the ANativeActivity instance representing the Android activity.
ANativeWindow*
Native window for rendering. NULL when no window is available.
AInputQueue*
Input event queue for processing touch, key, and motion events.

Code example: Basic NativeActivity

CMake configuration

Asset Manager

The Asset Manager API allows you to access files packaged in your app’s APK.

API reference

opaque struct
Manager object for accessing assets. Obtained from ANativeActivity.
opaque struct
Represents an open asset file. Use for reading asset contents.

Code example: Reading assets

Asset access modes

Logging

The Android logging API provides native logging that integrates with logcat.

API reference

function
Formatted logging function similar to printf. Most commonly used logging function.
function
Simple logging function for unformatted messages.

Log levels

2
Verbose logging. Typically compiled out in release builds.
3
Debug logging. Use for development and debugging.
4
Informational messages. Use for normal operation messages.
5
Warning messages. Use for potential issues.
6
Error messages. Use for error conditions.
7
Fatal error messages. Use for critical failures.

Code example: Logging utilities

CMake configuration

Storage Access Framework

Access files through Android’s Storage Access Framework (SAF) using file descriptors.
Direct file system access is restricted on Android 10 (API 29) and higher. Use SAF or app-specific directories.

Code example: Working with file descriptors

Configuration and System Info

Access device configuration and system information.

Code example: Device configuration

Additional Android-specific APIs

Access and share hardware graphics buffers for efficient rendering.Available from API 26+. Used for Vulkan, OpenGL ES interop, and camera integration.
Synchronize rendering with display refresh rate.Available from API 24+. Essential for smooth animations and game loops.
Add native trace events visible in Android Studio Profiler.Available from API 23+. Critical for performance profiling.
Manipulate Android Bitmap objects from native code.Available from API 8+. Useful for image processing.

Library reference

Android-specific libraries to link in your build configuration:

Next steps

Bionic status

Check POSIX compliance and available C library functions

Platform APIs

Learn about platform API availability and compatibility

Graphics guide

OpenGL ES and Vulkan rendering

Audio guide

High-performance audio with AAudio