About Bionic
Bionic is Android’s C library, math library, and dynamic linker. It provides a subset of standard C library functionality with Android-specific optimizations and modifications.Bionic is not fully POSIX-compliant. Always check API availability for your target Android version before using standard C library functions.
POSIX compliance
Bionic provides partial POSIX compliance with some differences from standard glibc implementations.Supported POSIX features
pthread APIs are fully supported with Android-specific extensions for thread naming and priority.
Standard file operations (open, read, write, close) are fully supported.
malloc, free, and related APIs with Android-specific allocators.
Socket APIs for network communication, including Unix domain sockets.
Limited or missing POSIX features
System V IPC
System V IPC
System V shared memory, semaphores, and message queues are not supported.Alternative: Use POSIX shared memory (
shm_open, mmap) or Android IPC mechanisms.Locale support
Locale support
Very limited locale support. Most locale functions are stubs.Impact: Functions like
setlocale(), nl_langinfo() have minimal functionality.Real-time extensions
Real-time extensions
Limited support for POSIX real-time extensions.Available: Basic timer APIs
Limited: Real-time signals, advanced scheduling
Limited: Real-time signals, advanced scheduling
Wide character support
Wide character support
Basic wide character support, but not all functions are implemented.Impact: Some
wchar.h functions may be missing or have limited functionality.Standard C library functions
String functions
All standard string functions are available across all Android API levels:Code example: Safe string operations
Math functions
Standard math library functions from<math.h>:
API availability by Android version
Android 5.0 (API 21) - Minimum supported
API 21 includes:- Complete pthread support
- Standard C11 features (except threads.h)
- Basic math functions
- File I/O and networking
Android 8.0 (API 26) - Major improvements
New in API 26:Create a stream that writes to a dynamically allocated buffer.
Secure random number generation (cryptographically secure).
Path pattern matching (globbing).
Android 9.0 (API 28) - String safety
New in API 28:Safe string copy with guaranteed null termination.
Safe string concatenation with size limits.
Android 12.0 (API 31) - Modern C features
New in API 31:C11 time function for high-resolution timestamps.
Allocate aligned memory (C11 standard).
Function availability table
Standard C functions by API level
| Function | API Level | Header | Notes |
|---|---|---|---|
pthread_* | 21+ | <pthread.h> | Full threading support |
posix_memalign | 21+ | <stdlib.h> | Aligned memory allocation |
getentropy | 26+ | <sys/random.h> | Secure random bytes |
glob | 26+ | <glob.h> | Pattern matching |
strlcpy | 28+ | <string.h> | Safe string copy |
strlcat | 28+ | <string.h> | Safe string concat |
timespec_get | 31+ | <time.h> | C11 time function |
aligned_alloc | 31+ | <stdlib.h> | C11 aligned allocation |
timespec_getres | 34+ | <time.h> | Timer resolution |
Math functions by API level
| Function | API Level | Header | Notes |
|---|---|---|---|
sin, cos, tan | 21+ | <math.h> | Basic trigonometry |
log2, exp2 | 21+ | <math.h> | Base-2 logarithm/exponent |
lgamma, tgamma | 21+ | <math.h> | Gamma functions |
nextafter | 21+ | <math.h> | Next representable value |
fma | 21+ | <math.h> | Fused multiply-add |
Threading APIs
Bionic provides full pthread support with Android-specific extensions.Code example: Thread creation
Code example: Mutexes and synchronization
Memory allocation
Bionic provides standard memory allocation with Android-specific optimizations.Available allocators
Standard memory allocation. Uses jemalloc on most Android versions.
Allocate and zero-initialize memory.
Resize previously allocated memory.
Allocate aligned memory. Available from API 21+.
Code example: Memory allocation patterns
Important differences from glibc
Key differences
- No System V IPC: Use POSIX alternatives or Android-specific IPC
- Limited locale support: Don’t rely on locale-specific formatting
- Different allocator: Memory allocation behavior may differ from glibc
- No
dlmopen: Only standarddlopenis supported - Different signal handling: Some signal behaviors differ from standard Linux
Code example: Portable code patterns
Official documentation
Android bionic status
Comprehensive status of Bionic APIs and POSIX compliance
Next steps
Platform APIs
Platform API availability and private vs public APIs
Android-specific APIs
NativeActivity, Asset Manager, and other Android APIs
Dynamic linker
Understanding Android’s dynamic linker
32-bit ABI issues
Known issues with 32-bit Android ABIs