Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ For an explanation of the layout of this repository, see

## Build and run

[![build](https://github.com/android/ndk-samples/actions/workflows/build.yml/badge.svg)](https://github.com/android/ndk-samples/actions)

1. Clone the repository
2. Open the whole project in Android Studio
3. Install CMake 4.1.0 via the SDK Manager (must be done manually until
https://issuetracker.google.com/443137057 is fixed).
4. Select the sample you want to run in the top bar (you may need to sync gradle
first)
5. 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.
1. Clone the repository.
2. Open the project in Android Studio (Ladybug or newer recommended).
3. The project will automatically configure the required **NDK** and **CMake** versions
defined in the [Version Catalog](gradle/libs.versions.toml).
4. Select the sample you want to run in the top bar.
5. Click the play button to run the sample.

You can also build the samples from the command line using the Gradle wrapper:
- macOS/Linux: `./gradlew build`
- Windows: `.\gradlew.bat build`

To build specific module/app you can use a command like: `./gradlew :camera:basic:tasks`

## I just want something to copy from as a starting point

Expand Down
2 changes: 1 addition & 1 deletion base/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22.1)
cmake_minimum_required(VERSION 4.1.0)
project(Base LANGUAGES CXX)

include(AppLibrary)
Expand Down
4 changes: 2 additions & 2 deletions base/src/main/cpp/logging_splitters.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <inttypes.h>
#include <time.h>
#include <cinttypes>
#include <ctime>

#include <format>

Expand Down
23 changes: 0 additions & 23 deletions bitmap-plasma/app/build.gradle

This file was deleted.

23 changes: 23 additions & 0 deletions bitmap-plasma/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id("ndksamples.android.application")
}

android {
namespace = "com.example.plasma"
defaultConfig {
applicationId = "com.example.plasma"
}
externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
}
}

buildFeatures {
prefab = true
}
}

dependencies {
implementation(project(":base"))
}
2 changes: 1 addition & 1 deletion bitmap-plasma/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22.1)
cmake_minimum_required(VERSION 4.1.0)
project(BitmapPlasma LANGUAGES CXX)

include(AppLibrary)
Expand Down
8 changes: 4 additions & 4 deletions bitmap-plasma/app/src/main/cpp/plasma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include <android/bitmap.h>
#include <android/log.h>
#include <jni.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>

#define LOG_TAG "libplasma"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.content.Context;
import android.view.View;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;
import android.view.View;

public class Plasma extends Activity
{
Expand Down
5 changes: 3 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -12,8 +13,8 @@ java {
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
package com.android.ndk.samples.buildlogic

import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.JavaVersion

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType

class AndroidApplicationConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
val libs = target.extensions.getByType<VersionCatalogsExtension>().named("libs")
val compileSdkVersion = libs.findVersion("compileSdk").get().requiredVersion.toInt()
val minSdkVersion = libs.findVersion("minSdk").get().requiredVersion.toInt()
val targetSdkVersion = libs.findVersion("targetSdk").get().requiredVersion.toInt()
val ndkVersionStr = libs.findVersion("ndk").get().requiredVersion
val cmakeVersionStr = libs.findVersion("cmake").get().requiredVersion
val javaVersion = JavaVersion.toVersion(libs.findVersion("javaTarget").get().requiredVersion)

with(target) {
with(pluginManager) {
apply("com.android.application")
}

extensions.configure<ApplicationExtension> {
compileSdk = Versions.COMPILE_SDK
ndkVersion = Versions.NDK
compileSdk = compileSdkVersion
ndkVersion = ndkVersionStr

externalNativeBuild {
cmake {
version = Versions.CMAKE
version = cmakeVersionStr
}
}

defaultConfig {
minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK
minSdk = minSdkVersion
targetSdk = targetSdkVersion

externalNativeBuild {
cmake {
Expand All @@ -51,8 +62,8 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
}
}
compileOptions {
sourceCompatibility = Versions.JAVA
targetCompatibility = Versions.JAVA
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

// Studio will not automatically pass logcat through ndk-stack, so we need to avoid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
package com.android.ndk.samples.buildlogic

import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType

class AndroidLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
val libs = target.extensions.getByType<VersionCatalogsExtension>().named("libs")
val compileSdkVersion = libs.findVersion("compileSdk").get().requiredVersion.toInt()
val minSdkVersion = libs.findVersion("minSdk").get().requiredVersion.toInt()
val targetSdkVersion = libs.findVersion("targetSdk").get().requiredVersion.toInt()
val ndkVersionStr = libs.findVersion("ndk").get().requiredVersion
val cmakeVersionStr = libs.findVersion("cmake").get().requiredVersion
val javaVersion = JavaVersion.toVersion(libs.findVersion("javaTarget").get().requiredVersion)

with(target) {
with(pluginManager) {
apply("com.android.library")
}

extensions.configure<LibraryExtension> {
compileSdk = Versions.COMPILE_SDK
ndkVersion = Versions.NDK
compileSdk = compileSdkVersion
ndkVersion = ndkVersionStr

externalNativeBuild {
cmake {
version = Versions.CMAKE
version = cmakeVersionStr
}
}

defaultConfig {
minSdk = Versions.MIN_SDK
minSdk = minSdkVersion
lint {
targetSdk = Versions.TARGET_SDK
targetSdk = targetSdkVersion
}
testOptions {
targetSdk = Versions.TARGET_SDK
targetSdk = targetSdkVersion
}
externalNativeBuild {
cmake {
Expand All @@ -53,8 +64,8 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
}
}
compileOptions {
sourceCompatibility = Versions.JAVA
targetCompatibility = Versions.JAVA
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

// Studio will not automatically pass logcat through ndk-stack, so we need to avoid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.android.ndk.samples.buildlogic

import com.android.build.api.dsl.ApplicationExtension

import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

class KotlinConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.android")
}
val libs = target.extensions.getByType<VersionCatalogsExtension>().named("libs")
val javaVersion = JavaVersion.toVersion(libs.findVersion("javaTarget").get().requiredVersion)

extensions.configure<ApplicationExtension> {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Versions.JAVA.toString()
}
with(target) {
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(javaVersion.toString()))
}
}
}
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion build.gradle → build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
}
31 changes: 0 additions & 31 deletions camera/basic/build.gradle

This file was deleted.

30 changes: 30 additions & 0 deletions camera/basic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
id("ndksamples.android.application")
}

android {
namespace = "com.sample.camera.basic"
defaultConfig {
applicationId = "com.sample.camera.basic"
externalNativeBuild {
cmake {
arguments.add("-DANDROID_STL=c++_static")
}
}
}
externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
}
}

buildFeatures {
prefab = true
}
}

dependencies {
implementation(project(":base"))
implementation(libs.appcompat)
implementation(project(":camera:camera-utils"))
}
Loading