Top Related Projects
Android NDK samples with Android Studio
Quick Overview
The android/ndk-samples repository is a collection of sample projects demonstrating the use of the Android Native Development Kit (NDK). It provides developers with practical examples of how to implement native code in Android applications, showcasing various NDK features and best practices.
Pros
- Offers a wide range of examples covering different NDK use cases
- Regularly updated to reflect the latest NDK features and Android Studio versions
- Includes detailed README files for each sample, explaining the purpose and implementation
- Serves as an excellent learning resource for developers new to NDK
Cons
- Some samples may become outdated as Android and NDK evolve
- Limited coverage of more advanced NDK topics
- May not include examples for all possible NDK use cases
- Requires a good understanding of C/C++ programming
Getting Started
To get started with the android/ndk-samples:
-
Clone the repository:
git clone https://github.com/android/ndk-samples.git
-
Open Android Studio and select "Open an Existing Project"
-
Navigate to the cloned repository and select the sample you want to explore
-
Build and run the sample on an emulator or physical device
-
Explore the code, focusing on the native implementation in the
cpp
directory and the Java/Kotlin code in thejava
orkotlin
directory -
Refer to the sample's README for specific instructions and explanations
Note: Ensure you have the latest version of Android Studio and the NDK installed before running the samples.
Competitor Comparisons
Android NDK samples with Android Studio
Pros of ndk-samples
- Comprehensive collection of NDK sample projects
- Well-documented examples covering various NDK use cases
- Regular updates and maintenance by the Android team
Cons of ndk-samples
- May contain more complex examples than necessary for beginners
- Some samples might be outdated or not follow the latest best practices
Code Comparison
ndk-samples:
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
ndk-samples:
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
Summary
Both ndk-samples repositories appear to be identical, as they are likely the same project. The comparison provided above is based on the general characteristics of the ndk-samples repository. The code comparison shows the same JNI function implementation, which is a common example in NDK tutorials. The repository serves as a valuable resource for developers looking to integrate native code into their Android applications using the NDK.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Android NDK Samples
This repository contains sample apps that use the Android NDK.
For an explanation of the layout of this repository, see ARCHITECTURE.md.
Build and run
- Clone the repository
- Open the whole project in Android Studio
- Select the sample you want to run in the top bar (you may need to sync gradle first)
- Click the play button to run the sample
You can also build the samples from the command line if you prefer. Use
./gradlew build
to build everything (if you're on Windows, use .\gradlew.bat
instead of ./gradlew
). For individual tasks, see ./gradlew tasks
. To see the
tasks for an individual sample, run the tasks
task for that directory. For
example, ./gradlew :camera:basic:tasks
will show the tasks for the
camera/basic
app.
I just want something to copy from as a starting point
The samples in this repository are generally not a good starting point for a production quality app. They aim to demonstrate individual NDK APIs, but often make sacrifices to be succinct that make them unsuitable for a production app. This is gradually changing, but for now you should not do this.
Now in Android is an excellent resource for production quality apps in general, but does not touch on NDK- specific issues. https://github.com/DanAlbert/ndk-app-template can help some with that until this repository is able to.
You're most likely best served by using the New Project wizard in Android Studio to create a new app, then using those resources and the samples here as a reference. Android Studio's "Native C++" template is a good starting point for typical applications that need to use some C++ via JNI. The "Game Activity" template is a good starting point for game-like apps (that is, apps that do not use the Android UI, but instead render their own UI using OpenGL or Vulkan).
Additional documentation
Support
If you've found an issue with a sample and you know how to fix it, please send us a PR!.
If you need to report a bug, where it needs to be filed depends on the type of issue:
- Problems with the samples themselves: https://github.com/googlesamples/android-ndk/issues
- Problems with the OS APIs: http://b.android.com (usually the Framework component)
- Problems with NDK (that is, the compiler): https://github.com/android/ndk/issues
For questions about using the NDK or the platform APIs, you can ask on:
- The NDK mailing list (best if you're not sure where else to ask)
- The Discussions tab of this repo (best for questions about the samples themselves)
- The NDK's Discussions (best for questions about the NDK compilers and build systems)
- Stack Overflow
Additional NDK samples:
- Google Play Game Samples with Android Studio
- Google Android Vulkan Tutorials
- Android Vulkan API Basic Samples
- Android High Performance Audio
License
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
https://www.apache.org/licenses/LICENSE-2.0
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.
Top Related Projects
Android NDK samples with Android Studio
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot