Android NDK samples with Android Studio


NDK Samples build

This repository contains Android NDK samples with Android Studio C++ integration.

These samples use the new CMake Android plugin with C++ support.

Samples could also be built with other build systems:

  • for ndk-build with Android Studio, refer to directory other-builds/ndkbuild
  • for gradle-experimental plugin, refer to directory other-builds/experimental. Note that gradle-experimental does not work with unified headers yet: use NDK version up to r15 and Android Studio up to version 2.3. When starting new project, please use CMake or ndk-build plugin.

Additional Android Studio samples:


Known Issues

For samples using build system with ndk-build see the android-mk branch.

Build Steps

  • With Android Studio: "Open An Existing Android Studio Project" or "File" > "Open", then navigate to & select project's build.gradle file.
  • On Command Line: set up ANDROID_HOME and ANDROID_NDK_HOME to your SDK and NDK path, cd to individual sample dir, and do "gradlew assembleDebug"


For any issues you found in these samples, please

For Android NDK generic questions, please ask on Stack Overflow, Android teams are periodically monitoring questions there.


Copyright 2018 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


  • Unable to step into hello-libs

    Unable to step into hello-libs

    I am running Android Studio 2.2 Preview 4 on Linux Mint 17.2 64 bit using a Nexus 5 device.

    I am able to debug into

    Java_com_example_hellolibs_MainActivity_stringFromJNI(JNIEnv *env, jobject thiz),

    but I am unable to debug into

    GMATH_EXPORT unsigned gpower(unsigned n)

    GPERF_EXPORT uint64_t GetTicks(void)

    The only difference I can see is that these are located in a module, but maybe there is some other problem.

    How can I debug into these C++ functions?

    opened by bessermt 65
  • Create/port cmake samples

    Create/port cmake samples

    android studio 2.2 supports cmake / ndk-build, we should add or porting existing samples. one option is to port the existing gradle samples to cmake, and put them into "master-cmake" branch. share your thought in this issue here so we could talk about it.

    opened by ggfan 30
  • NDK Open SLES SLPlayItf uriPlayerPlay Not Working

    NDK Open SLES SLPlayItf uriPlayerPlay Not Working

    When running the example code to play the audio stream from a URL using URI player (SLPlayItf uriPlayerPlay). Either nothing plays, or after clicking on the "URI Soundtrack" Button in the example, followed by "Play URI" Button, it will throw a crash, with the following spewed out into the log:-

    "A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 2880 (ALooper)

        [ 06-10 08:25:05.426  1177: 1177 W/         ]
        debuggerd: handling request: pid=2364 uid=10061 gid=10061 tid=2880"
    bug content 
    opened by developeruk 28
  • changing delay time in audio echo‏

    changing delay time in audio echo‏


    I tried to add seekBar for changing delay on RealTime but it doesn't work (no sound or app crash) this my code(based on

    Could you help ?

    Thanks, Alex

    int delay_factor=1;
    protected void onCreate(Bundle savedInstanceState) {
        controlButton = (Button)findViewById((;
        statusView = (TextView)findViewById(;
        toggleFilter = (Button)findViewById((;
        final SeekBar delayBar = (SeekBar)findViewById(;
        delayBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                //  statusView.setText(""+Integer.parseInt(nativeSampleBufSize)*delay_factor);
            public void onStartTrackingTouch(SeekBar seekBar) {
            public void onStopTrackingTouch(SeekBar seekBar) {
        // initialize native audio system
        if (supportRecording) {
            createSLEngine(Integer.parseInt(nativeSampleRate), Integer.parseInt(nativeSampleBufSize));
    void change_delay(int delay_factor)
        if(isPlaying && supportRecording)
            createSLEngine(Integer.parseInt(nativeSampleRate), Integer.parseInt(nativeSampleBufSize)*delay_factor);
        else if(supportRecording)
           if (isPlaying) {
           createSLEngine(Integer.parseInt(nativeSampleRate), Integer.parseInt(nativeSampleBufSize)*delay_factor);
    opened by alexd555 24
  • I am getting this error.  i haven't changed anything in the code

    I am getting this error. i haven't changed anything in the code

    A/CAMERA-SAMPLE: No Camera Available on the device A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 13801 (ple.textureview)

        [ 12-12 11:44:03.304   463:  463 W/         ]
        debuggerd: handling request: pid=13801 uid=10233 gid=10233 tid=13801

    Mobile model : MI5 (lolipop)

    opened by kishoreangadi 22
  • audio-echo sample doesn't work on Pixel 2 when recording audio over Bluetooth

    audio-echo sample doesn't work on Pixel 2 when recording audio over Bluetooth

    Tested on a Pixel 2 running 8.1.0 (patch Feb 5 2018).

    Android Studio 3.0 BuildToolsVersion 26.0.3

    This appears to reproduce with all Bluetooth headsets. I modified the sample to use startBluetoothSco() before recording:

    For background, this is an issue we're observing with our app that uses Nuance VoCon (an NDK library that uses OpenSL) for voice recognition. It works well on all other phones, just not the Pixel 2. Now that it reproduces here, it appears that the problem may occur at a lower level than VoCon.

    opened by 6bangs 20
  • Add HPF on Real Time

    Add HPF on Real Time

    Hi, I want to add HPF to

    I try this

    double filter[]={-0.000271644477087926,0.00231682081656234,-0.00697762679239381,0.0113431078907557,-0.00922785019978973,-0.000953863100870534,0.00985593896141045,-0.00555013199491495,-0.00869288595337110,0.0130688967200457,0.00298808043964922,-0.0197522326251256,0.00894497147708418,0.0214370330423526,-0.0266004895962514,-0.0129511674987413,0.0473297694426478,-0.0123916710107896,-0.0669754812188437,0.0708843498739455,0.0810696191193916,-0.305755100930970,0.413804336148547,-0.305755100930970,0.0810696191193916,0.0708843498739455,-0.0669754812188437,-0.0123916710107896,0.0473297694426478,-0.0129511674987413,-0.0266004895962514,0.0214370330423526,0.00894497147708418,-0.0197522326251256,0.00298808043964922,0.0130688967200457,-0.00869288595337110,-0.00555013199491495,0.00985593896141045,-0.000953863100870534,-0.00922785019978973,0.0113431078907557,-0.00697762679239381,0.00231682081656234,-0.000271644477087926};
    double * convolution(uint8_t *x,int len_signal, double *filter, int len_filter)
         double *y=new double[len_signal+len_filter];
         int length = len_signal+len_filter;
         for (int n=0;n<length;n++)
             for(int k=0;k<length;k++)
                 if (n-k >=0 && n-k <length)
                     y[n] += x[n-k]*filter[k];
         return y;
    void ece420ProcessFrame(sample_buf *dataBuf) {
        dataBuf->buf_= (uint8_t *) convolution(dataBuf->buf_, dataBuf->size_, filter, 45);

    Can you help me, please ?

    Thanks, Alex

    opened by alexd555 20
  • Unit test sample

    Unit test sample

    cc: @proppy Adding a sample that has Android InstrumentationTests and Java UnitTests running correctly to address #79

    My sample is based on the Hello World sample, if simple to show the basics of the configuration and how to test them. The UnitTest part it was a little bit tricky because I had to isolate the Java code, and that means to create stubs of the native methods and not to load the static block that loads the JNI library.

    This is the first part, I'm planning to add tests to the C code, but I don't have a lot of knowledge so I'm doing my research.

    P.S: As a side note, you will notice this is using and :gradle-experimental:0.3.0-alpha2, I tried with previous versions but it wasn't compiling.



    opened by rcgonzalezf 20
  • Sample hello-jni won't compile

    Sample hello-jni won't compile

    UNEXPECTED TOP-LEVEL EXCEPTION: bad class file magic (cafebabe) or version (0034.0000)
    ...while parsing com/example/hellojni/R.class
    6 errors; aborting               
    :app:dexAllDebug FAILED          
    FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':app:dexAllDebug'.
    > org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1
    * Try:        
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    Total time: 6.0 secs
    opened by gengjiawen 20
  • can not run on the latest Android Studio 3.0

    can not run on the latest Android Studio 3.0

    It can not run at the latest Android Studio3.0. Android Studio 3.0 Build #AI-171.4408382, built on October 21, 2017 JRE: 1.8.0_152-release-915-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 7 6.1

    It crashed at LoadProgress(): void PlayScene::LoadProgress() { // try to load save file mSavedCheckpoint = 0;

    LOGD("Attempting to load: %s", mSaveFileName);
    FILE *f = fopen(mSaveFileName, "r");   **// f is NULL**
    bool hasLocalFile = false;
    if (f) {

    ... }

    opened by Schumanzou 19
  • Latest Android Studio New C++ Project fails to build

    Latest Android Studio New C++ Project fails to build

    Just installed android studio, latest version on everything. Created a new native C++ project, and modified absolutely nothing. Yesterday the build worked properly. Today I have this errors and I can't figure out why. Maybe an update happened today and broken everything ?

    Build command failed. Error while executing process D:\AndroidTools\android-sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HD:\Work\Test3\app\src\main\cpp -BD:\Work\Test3\app.externalNativeBuild\cmake\debug\x86_64 -DANDROID_ABI=x86_64 -DANDROID_PLATFORM=android-21 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\Work\Test3\app\build\intermediates\cmake\debug\obj\x86_64 -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=D:\AndroidTools\android-sdk\ndk-bundle -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=D:\AndroidTools\android-sdk\ndk-bundle\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\AndroidTools\android-sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja} -- Check for working C compiler: D:/AndroidTools/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- Check for working C compiler: D:/AndroidTools/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- broken -- Configuring incomplete, errors occurred! See also "D:/Work/Test3/app/.externalNativeBuild/cmake/debug/x86_64/CMakeFiles/CMakeOutput.log". See also "D:/Work/Test3/app/.externalNativeBuild/cmake/debug/x86_64/CMakeFiles/CMakeError.log".

    CMake Error at D:/AndroidTools/android-sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message): The C compiler "D:/AndroidTools/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe" is not able to compile a simple test program.

    It fails with the following output:

    Change Dir: D:/Work/Test3/app/.externalNativeBuild/cmake/debug/x86_64/CMakeFiles/CMakeTmp

    Run Build Command:"D:\AndroidTools\android-sdk\cmake\3.6.4111459\bin\ninja.exe" "cmTC_b514a"

    [1/2] Building C object CMakeFiles/cmTC_b514a.dir/testCCompiler.c.o

    [2/2] Linking C executable cmTC_b514a

    FAILED: cmd.exe /C "cd . && D:\AndroidTools\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=x86_64-none-linux-android21 --gcc-toolchain=D:/AndroidTools/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot D:/AndroidTools/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections CMakeFiles/cmTC_b514a.dir/testCCompiler.c.o -o cmTC_b514a -latomic -lm && cd ."

    clang.exe: error: unable to execute command: Couldn't execute program 'D:/AndroidTools/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin\ld': Unknown error (0xC1)

    clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)

    ninja: build stopped: subcommand failed.

    CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt

    opened by Amandrix 17
  • how to compiler sve in Android system

    how to compiler sve in Android system

    In linux system,I try to use in Android compiler system to compile an executable file including SVE intrinsics, which is supported in armv8.2, and the system config as follows:

    • TARGET_ARCH=arm64;
    • TARGET_ARCH_VARIANT=armv8-2a;
    • TARGET_CPU_VARIANT=cortex-a76
    • TARGET_2ND_ARCH=arm;
    • TARGET_2ND_ARCH_VARIANT=armv8-2a
    • TARGET_2ND_CPU_VARIANT=cortex-a55
    • HOST_ARCH=x86_64
    • HOST_2ND_ARCH=x86
    • HOST_OS=linux

    And here are the steps I build: source build/ lunch, I choose a platform described as above; mm, build the modules in the SVE instrinsics directory,and the is in the same deirctory;

    And the is

    LOCAL_PATH:= $(call my-dir)
    ROOT_DIR := $(LOCAL_PATH)/..
    include $(CLEAR_VARS)
    LOCAL_SRC_FILES := $(ROOT_DIR)/Project1/main.cpp
    LOCAL_CFLAGS += -mfloat-abi=softfp -mfpu=neon -msve-vector-bits=256
    LOCAL_LDLIBS  += -lc -ldl -lm -lz -llog -fPIE
    APP_CPPFLAGS  +=-std=c++11
    ifeq($(TARGET_ARCH_ABI), arm64-v8a)
    include $(BUILD_EXECUTABLE)

    But some errors I met, it shows thaterror in backend:don't know how to legalize this scalable vector size. How to solve this problem?

    opened by xxxxxxLD 1
  • timestamp of camera and IMU

    timestamp of camera and IMU

    I used NDK API to get the camera & IMU sensor data(including timestamp) simultaneously. But it seems that the timestamps of camera and IMU are NOT from a same clock system. So is there some way to get the 2 sensor's timestamp that are synchronous completely? Thanks!

    opened by jianchong-chen 0
  • Updating hello-jnicallback to support large screen devices

    Updating hello-jnicallback to support large screen devices

    Timer does not restart on configuration changes and utilizes a ViewModel to preserve state. Timer functionality refactored into this ViewModel. Button added to start and stop. Changed StopTimer to stopTimer to match naming convention.

    opened by MattMonasch 0
  • I want to compile a bluetooth executable using ndk-build without any java language

    I want to compile a bluetooth executable using ndk-build without any java language

    Hi. I want to compile with ndk-build without any java language. The purpose is to generate a native executable program. However, the linux dynamic link library used when compiling the bluetooth module does not support armV8, which causes the compilation to fail. Excuse me, can ndk-build compile bluetooth directly, and if so, where can I find the required header files and dynamic link libraries.

    opened by accsky 0
My Code Samples and Mods for - CODI6 ARGB CONTROLLER -

Gelid-Codi6-ARGB-Controller A small collection of codes for codi6 from Gelid Solutions. try and error ..... my led devices : 7 * ARCTIC P12 PWM PST A-

Klaus 1 Oct 25, 2021
Collection of Vulkan samples

This repository holds many samples, showing various aspect of Vulkan, debugging tips and usage of other Nvidia tools.

NVIDIA DesignWorks Samples 52 Sep 25, 2022
Generate representative samples from Pwned Passwords (HIBP)

Generate representative samples from Pwned Passwords (HIBP) This program generates representative samples from Pwned Passwords (HIBP), taking the coun

Solar Designer 11 Jun 15, 2022
Bungie's Oni modified so it compiles with Microsoft Visual Studio 2019.

OniFoxed What's this? This is a modified variant of the recently leaked Oni source code so that it compiles under Microsoft Visual Studio 2019 with so

Mark Sowden 54 Sep 24, 2022
A D++ Discord Bot template for Visual Studio 2019 (x64 and x86)

D++ Windows Bot Template A D++ Discord Bot template for Visual Studio 2019 (x64 and x86, release and debug). The result of this tutorial. This templat 22 Sep 14, 2022
Lo-Fi SAMD21 based mini chip tune synthesizer - Seeed Studio - Seeeduino XIAO arduino project

samd21_mini_synth Lo-Fi SAMD21 based mini chip tune synthesizer Seeed Studio - Seeeduino XIAO arduino project link to the video Description This time

Marcel 7 Sep 23, 2022
A Visual Studio template used to create Cobalt Strike BOFs

Introduction Cobalt Strike beacon object files (BOFs) is a feature that added to the beacon in order to allow rapid beacon extendibility in a more OPS

Securify 150 Sep 22, 2022
Bot for the Cee.Studio server

cee-bot Bot for the Cee.Studio server. Getting Started Open config.json and match the cee_bot field to your server primitives Head to listeners/ and f 0 Sep 12, 2022
A creative composition studio for Scheme hackers.

Flux Compose A creative composition studio for Scheme hackers. What is it? This project is (or more accurately, will be) a studio for creative composi

Flux Harmonic 20 Sep 21, 2022
Sharpmake is an open-source C#-based solution for generating project definition files, such as Visual Studio projects and solutions, GNU makefiles, Xcode projects, etc.

Sharpmake Introduction Sharpmake is a generator for Visual Studio projects and solutions. It is similar to CMake and Premake, but it is designed for s

Ubisoft 763 Sep 29, 2022
Visual Studio Extension that installs additional color themes

Using this Extension Download and install the extension Restart Visual Studio Navigate to Tools > Options > Environment > General and select your colo

Microsoft 327 Sep 21, 2022
Visual Studio Test Adapter for Catch2

Test Adapter for Catch2 Within Visual Studio, the Test Explorer is a convenient way to run and debug unit tests. This test adapter adds support for th

null 90 Aug 15, 2022
A Visual Studio extension containing a collection of tools to help contributing code to the Chromium project.

VsChromium VsChromium is a Visual Studio Extension containing a collection of tools useful for editing, navigating and debugging code. VsChromium was

The Chromium Project 254 Sep 12, 2022
Visual Studio native debugger extension to help debug native applications using Mono.

Unity Mixed Callstack UnityMixedCallstack is a Visual Studio 2017/2019 extension to help debug native applications embedding Mono, like Unity. If you

Unity Technologies 79 Sep 30, 2022
Useful UE4 Visual Studio extensions.

UE4 Smarter Macro Indenting This extension was designed to fix the unnecessary and annoying "smart" indenting that Visual Studio likes to do around va

Chris Pawlukowsky 243 Aug 16, 2022
Visual Studio extension for assembly syntax highlighting and code completion in assembly files and the disassembly window

Asm-Dude Assembly syntax highlighting and code assistance for assembly source files and the disassembly window for Visual Studio 2015, 2017 and 2019.

Henk-Jan Lebbink 4k Sep 29, 2022
A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files

HLSL Tools for Visual Studio This extension is for Visual Studio 2017 / 2019. Go here for the Visual Studio Code extension. HLSL Tools is a Visual Stu

Tim Jones 413 Sep 29, 2022
Half-Life Singleplayer SDK 2.3, updated to compile with Visual Studio 2019. Provided as-is with no further support. See the README for more information.


Sam Vanheer 5 Apr 9, 2022
A customized LGL Android mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android

PUBG Mobile ESP Mod Menu A customized LGL mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android. Everything are fixed so it works with both

null 42 Mar 19, 2022