diff --git a/README.md b/README.md index bb66ef8e9..5f43c31f3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/base/src/main/cpp/CMakeLists.txt b/base/src/main/cpp/CMakeLists.txt index 9e4fb549f..f1e0c0935 100644 --- a/base/src/main/cpp/CMakeLists.txt +++ b/base/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(Base LANGUAGES CXX) include(AppLibrary) diff --git a/base/src/main/cpp/logging_splitters.h b/base/src/main/cpp/logging_splitters.h index 6795b3ba0..40ca256dd 100644 --- a/base/src/main/cpp/logging_splitters.h +++ b/base/src/main/cpp/logging_splitters.h @@ -16,8 +16,8 @@ #pragma once -#include -#include +#include +#include #include diff --git a/bitmap-plasma/app/build.gradle b/bitmap-plasma/app/build.gradle deleted file mode 100644 index 4d7153609..000000000 --- a/bitmap-plasma/app/build.gradle +++ /dev/null @@ -1,23 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.example.plasma' - defaultConfig { - applicationId 'com.example.plasma' - } - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") -} diff --git a/bitmap-plasma/app/build.gradle.kts b/bitmap-plasma/app/build.gradle.kts new file mode 100644 index 000000000..36d7c76ae --- /dev/null +++ b/bitmap-plasma/app/build.gradle.kts @@ -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")) +} diff --git a/bitmap-plasma/app/src/main/cpp/CMakeLists.txt b/bitmap-plasma/app/src/main/cpp/CMakeLists.txt index 62aa9b738..cf63f76c3 100644 --- a/bitmap-plasma/app/src/main/cpp/CMakeLists.txt +++ b/bitmap-plasma/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(BitmapPlasma LANGUAGES CXX) include(AppLibrary) diff --git a/bitmap-plasma/app/src/main/cpp/plasma.cpp b/bitmap-plasma/app/src/main/cpp/plasma.cpp index c7875183d..9c72fdf35 100644 --- a/bitmap-plasma/app/src/main/cpp/plasma.cpp +++ b/bitmap-plasma/app/src/main/cpp/plasma.cpp @@ -17,10 +17,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define LOG_TAG "libplasma" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) diff --git a/bitmap-plasma/app/src/main/java/com/example/plasma/Plasma.java b/bitmap-plasma/app/src/main/java/com/example/plasma/Plasma.java index 753c1076a..4f41876aa 100644 --- a/bitmap-plasma/app/src/main/java/com/example/plasma/Plasma.java +++ b/bitmap-plasma/app/src/main/java/com/example/plasma/Plasma.java @@ -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 { diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 7998a1bad..c9c7c11ac 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -12,8 +13,8 @@ java { } tasks.withType().configureEach { - kotlinOptions { - jvmTarget = JavaVersion.VERSION_17.toString() + compilerOptions { + jvmTarget.set(JvmTarget.JVM_17) } } diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt index 80085c899..6573174f7 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt @@ -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 { override fun apply(target: Project) { + val libs = target.extensions.getByType().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 { - 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 { @@ -51,8 +62,8 @@ class AndroidApplicationConventionPlugin : Plugin { } } 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 diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt index c697c99e6..dea4d1b72 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt @@ -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 { override fun apply(target: Project) { + val libs = target.extensions.getByType().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 { - 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 { @@ -53,8 +64,8 @@ class AndroidLibraryConventionPlugin : Plugin { } } 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 diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt index 4b031da8c..9fcba81bf 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/KotlinConventionPlugin.kt @@ -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 { override fun apply(target: Project) { - with(target) { - with(pluginManager) { - apply("org.jetbrains.kotlin.android") - } + val libs = target.extensions.getByType().named("libs") + val javaVersion = JavaVersion.toVersion(libs.findVersion("javaTarget").get().requiredVersion) - extensions.configure { - tasks.withType().configureEach { - kotlinOptions { - jvmTarget = Versions.JAVA.toString() - } + with(target) { + tasks.withType().configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.fromTarget(javaVersion.toString())) } } } diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt deleted file mode 100644 index 5980a1549..000000000 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.android.ndk.samples.buildlogic - -import org.gradle.api.JavaVersion - -object Versions { - const val COMPILE_SDK = 35 - const val TARGET_SDK = 35 - const val MIN_SDK = 21 - const val NDK = "29.0.14206865" // r29 - const val CMAKE = "4.1.0" - val JAVA = JavaVersion.VERSION_1_8 -} diff --git a/build.gradle b/build.gradle.kts similarity index 78% rename from build.gradle rename to build.gradle.kts index 8967292d3..9693c98c0 100644 --- a/build.gradle +++ b/build.gradle.kts @@ -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 } diff --git a/camera/basic/build.gradle b/camera/basic/build.gradle deleted file mode 100644 index b6b115654..000000000 --- a/camera/basic/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.camera.basic' - defaultConfig { - applicationId 'com.sample.camera.basic' - minSdkVersion 24 - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") - implementation libs.appcompat - implementation project(":camera:camera-utils") -} diff --git a/camera/basic/build.gradle.kts b/camera/basic/build.gradle.kts new file mode 100644 index 000000000..02db38c02 --- /dev/null +++ b/camera/basic/build.gradle.kts @@ -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")) +} diff --git a/camera/basic/src/main/cpp/CMakeLists.txt b/camera/basic/src/main/cpp/CMakeLists.txt index 5f7aa6107..c6504c424 100644 --- a/camera/basic/src/main/cpp/CMakeLists.txt +++ b/camera/basic/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(CameraBasic LANGUAGES C CXX) include(AppLibrary) diff --git a/camera/basic/src/main/cpp/camera_engine.h b/camera/basic/src/main/cpp/camera_engine.h index d10ffc6ce..0acbc25a5 100644 --- a/camera/basic/src/main/cpp/camera_engine.h +++ b/camera/basic/src/main/cpp/camera_engine.h @@ -63,7 +63,7 @@ class CameraEngine { int GetDisplayRotation(void); struct android_app* app_; - ImageFormat savedNativeWinRes_; + ImageFormat savedNativeWinRes_{}; bool cameraGranted_; int rotation_; volatile bool cameraReady_; diff --git a/camera/basic/src/main/cpp/camera_manager.cpp b/camera/basic/src/main/cpp/camera_manager.cpp index b02fe9c60..e25b0232d 100644 --- a/camera/basic/src/main/cpp/camera_manager.cpp +++ b/camera/basic/src/main/cpp/camera_manager.cpp @@ -35,7 +35,7 @@ static const int64_t kMaxExposureTime = 250000000; NDKCamera::NDKCamera() : cameraMgr_(nullptr), - activeCameraId_(""), + activeCameraId_(), cameraFacing_(ACAMERA_LENS_FACING_BACK), cameraOrientation_(0), outputContainer_(nullptr), diff --git a/camera/basic/src/main/cpp/camera_manager.h b/camera/basic/src/main/cpp/camera_manager.h index 5993f7761..cdd544cb6 100644 --- a/camera/basic/src/main/cpp/camera_manager.h +++ b/camera/basic/src/main/cpp/camera_manager.h @@ -77,7 +77,7 @@ class NDKCamera { std::vector requests_; ACaptureSessionOutputContainer* outputContainer_; - ACameraCaptureSession* captureSession_; + ACameraCaptureSession* captureSession_{}; CaptureSessionState captureSessionState_; // set up exposure control diff --git a/camera/camera-utils/build.gradle.kts b/camera/camera-utils/build.gradle.kts index 80d2dae4c..19d191e5a 100644 --- a/camera/camera-utils/build.gradle.kts +++ b/camera/camera-utils/build.gradle.kts @@ -5,10 +5,6 @@ plugins { android { namespace = "com.android.ndk.samples.camera.utils" - defaultConfig { - minSdk = 24 - } - externalNativeBuild { cmake { path = file("src/main/cpp/CMakeLists.txt") diff --git a/camera/camera-utils/src/main/cpp/CMakeLists.txt b/camera/camera-utils/src/main/cpp/CMakeLists.txt index f017a01d5..f8473966a 100644 --- a/camera/camera-utils/src/main/cpp/CMakeLists.txt +++ b/camera/camera-utils/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(CameraCommon LANGUAGES CXX) include(AppLibrary) diff --git a/camera/texture-view/build.gradle b/camera/texture-view/build.gradle deleted file mode 100644 index 1bce44b8b..000000000 --- a/camera/texture-view/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.textureview' - defaultConfig { - applicationId "com.sample.textureview" - minSdkVersion 24 - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation libs.androidx.core - implementation project(":base") - implementation project(":camera:camera-utils") -} diff --git a/camera/texture-view/build.gradle.kts b/camera/texture-view/build.gradle.kts new file mode 100644 index 000000000..ab724a907 --- /dev/null +++ b/camera/texture-view/build.gradle.kts @@ -0,0 +1,31 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.sample.textureview" + defaultConfig { + applicationId = "com.sample.camera.textureview" + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + } +} + +dependencies { + implementation(libs.androidx.core) + implementation(project(":base")) + implementation(project(":camera:camera-utils")) +} diff --git a/camera/texture-view/src/main/cpp/CMakeLists.txt b/camera/texture-view/src/main/cpp/CMakeLists.txt index baf7a4219..6f36c8768 100644 --- a/camera/texture-view/src/main/cpp/CMakeLists.txt +++ b/camera/texture-view/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(CameraTextureView LANGUAGES CXX) include(AppLibrary) diff --git a/camera/texture-view/src/main/cpp/camera_engine.h b/camera/texture-view/src/main/cpp/camera_engine.h index 06e6a24fe..8eb3b897b 100644 --- a/camera/texture-view/src/main/cpp/camera_engine.h +++ b/camera/texture-view/src/main/cpp/camera_engine.h @@ -48,6 +48,6 @@ class CameraAppEngine { int32_t requestHeight_; jobject surface_; NDKCamera* camera_; - ImageFormat compatibleCameraRes_; + ImageFormat compatibleCameraRes_{}; }; #endif // __CAMERA_ENGINE_H__ diff --git a/camera/texture-view/src/main/cpp/camera_manager.cpp b/camera/texture-view/src/main/cpp/camera_manager.cpp index ded26b395..672a8e14b 100644 --- a/camera/texture-view/src/main/cpp/camera_manager.cpp +++ b/camera/texture-view/src/main/cpp/camera_manager.cpp @@ -37,7 +37,7 @@ static const uint64_t kMaxExposureTime = static_cast(250000000); NDKCamera::NDKCamera() : cameraMgr_(nullptr), - activeCameraId_(""), + activeCameraId_(), cameraFacing_(ACAMERA_LENS_FACING_BACK), cameraOrientation_(0), outputContainer_(nullptr), diff --git a/camera/texture-view/src/main/cpp/camera_manager.h b/camera/texture-view/src/main/cpp/camera_manager.h index 1f5084365..1903f488e 100644 --- a/camera/texture-view/src/main/cpp/camera_manager.h +++ b/camera/texture-view/src/main/cpp/camera_manager.h @@ -87,7 +87,7 @@ class NDKCamera { std::vector requests_; ACaptureSessionOutputContainer* outputContainer_; - ACameraCaptureSession* captureSession_; + ACameraCaptureSession* captureSession_{}; CaptureSessionState captureSessionState_; // set up exposure control diff --git a/endless-tunnel/app/build.gradle b/endless-tunnel/app/build.gradle.kts similarity index 72% rename from endless-tunnel/app/build.gradle rename to endless-tunnel/app/build.gradle.kts index 193a32f21..705595873 100644 --- a/endless-tunnel/app/build.gradle +++ b/endless-tunnel/app/build.gradle.kts @@ -15,25 +15,24 @@ */ plugins { - id "ndksamples.android.application" + id("ndksamples.android.application") } android { - namespace 'com.google.sample.tunnel' + namespace = "com.google.sample.tunnel" defaultConfig { - applicationId 'com.google.sample.tunnel' - versionCode 1 - versionName '1.0' + applicationId = "com.google.sample.tunnel" + versionCode = 1 + versionName = "1.0" externalNativeBuild { cmake { - arguments '-DANDROID_STL=c++_static' + arguments.add("-DANDROID_STL=c++_static") } } } externalNativeBuild { cmake { - path 'src/main/cpp/CMakeLists.txt' + path = file("src/main/cpp/CMakeLists.txt") } } } - diff --git a/endless-tunnel/app/src/main/cpp/CMakeLists.txt b/endless-tunnel/app/src/main/cpp/CMakeLists.txt index 7a2f89c01..d963cc1d9 100644 --- a/endless-tunnel/app/src/main/cpp/CMakeLists.txt +++ b/endless-tunnel/app/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(EndlessTunnel LANGUAGES C CXX) include(AppLibrary) diff --git a/exceptions/app/build.gradle b/exceptions/app/build.gradle deleted file mode 100644 index 3b78835d1..000000000 --- a/exceptions/app/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -plugins { - id "ndksamples.android.application" - id "ndksamples.android.kotlin" -} - -android { - namespace 'com.example.exceptions' - - defaultConfig { - applicationId "com.example.exceptions" - versionCode 1 - versionName "1.0" - } - - externalNativeBuild { - cmake { - path file('src/main/cpp/CMakeLists.txt') - } - } - - buildFeatures { - prefab true - viewBinding true - } -} - -dependencies { - implementation libs.appcompat - implementation libs.material - implementation libs.androidx.constraintlayout - implementation project(":base") -} \ No newline at end of file diff --git a/exceptions/app/build.gradle.kts b/exceptions/app/build.gradle.kts new file mode 100644 index 000000000..3ebadb974 --- /dev/null +++ b/exceptions/app/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + id("ndksamples.android.application") + id("ndksamples.android.kotlin") +} + +android { + namespace = "com.example.exceptions" + + defaultConfig { + applicationId = "com.example.exceptions" + versionCode = 1 + versionName = "1.0" + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + viewBinding = true + } +} + +dependencies { + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.androidx.constraintlayout) + implementation(project(":base")) +} diff --git a/exceptions/app/src/main/cpp/CMakeLists.txt b/exceptions/app/src/main/cpp/CMakeLists.txt index 29c6ec9f7..b56419687 100644 --- a/exceptions/app/src/main/cpp/CMakeLists.txt +++ b/exceptions/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(exceptions LANGUAGES CXX) include(AppLibrary) diff --git a/exceptions/app/src/main/java/com/example/exceptions/MainActivity.kt b/exceptions/app/src/main/java/com/example/exceptions/MainActivity.kt index 2747ad13b..05d1f23d4 100644 --- a/exceptions/app/src/main/java/com/example/exceptions/MainActivity.kt +++ b/exceptions/app/src/main/java/com/example/exceptions/MainActivity.kt @@ -2,7 +2,6 @@ package com.example.exceptions import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.widget.TextView import com.example.exceptions.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { diff --git a/gles3jni/app/build.gradle b/gles3jni/app/build.gradle deleted file mode 100644 index 8df6545c1..000000000 --- a/gles3jni/app/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.android.gles3jni' - - defaultConfig { - applicationId 'com.android.gles3jni' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") -} diff --git a/gles3jni/app/build.gradle.kts b/gles3jni/app/build.gradle.kts new file mode 100644 index 000000000..ca06c2b9f --- /dev/null +++ b/gles3jni/app/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.android.gles3jni" + + defaultConfig { + applicationId = "com.android.gles3jni" + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + } +} + +dependencies { + implementation(project(":base")) +} diff --git a/gles3jni/app/src/main/cpp/CMakeLists.txt b/gles3jni/app/src/main/cpp/CMakeLists.txt index 972b5aae6..eae0e3751 100644 --- a/gles3jni/app/src/main/cpp/CMakeLists.txt +++ b/gles3jni/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(Gles3Jni LANGUAGES CXX) include(AppLibrary) diff --git a/gles3jni/app/src/main/cpp/gles3jni.cpp b/gles3jni/app/src/main/cpp/gles3jni.cpp index 236db9c8a..998ceec70 100644 --- a/gles3jni/app/src/main/cpp/gles3jni.cpp +++ b/gles3jni/app/src/main/cpp/gles3jni.cpp @@ -18,9 +18,9 @@ #include #include -#include -#include -#include +#include +#include +#include const Vertex QUAD[4] = { // Square with diagonal < 2 so that it fits in a [-1 .. 1]^2 square diff --git a/gles3jni/app/src/main/cpp/gles3jni.h b/gles3jni/app/src/main/cpp/gles3jni.h index 9895f238d..3bfb5276c 100644 --- a/gles3jni/app/src/main/cpp/gles3jni.h +++ b/gles3jni/app/src/main/cpp/gles3jni.h @@ -19,7 +19,7 @@ #include #include -#include +#include #define DEBUG 1 diff --git a/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIActivity.java b/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIActivity.java index 542741859..7657abd5f 100644 --- a/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIActivity.java +++ b/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIActivity.java @@ -18,10 +18,6 @@ import android.app.Activity; import android.os.Bundle; -import android.util.Log; -import android.view.WindowManager; - -import java.io.File; public class GLES3JNIActivity extends Activity { diff --git a/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIView.java b/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIView.java index b0e013357..84b63d61b 100644 --- a/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIView.java +++ b/gles3jni/app/src/main/java/com/android/gles3jni/GLES3JNIView.java @@ -17,17 +17,8 @@ package com.android.gles3jni; import android.content.Context; -import android.graphics.PixelFormat; import android.opengl.GLSurfaceView; -import android.util.AttributeSet; -import android.util.Log; -import android.view.KeyEvent; -import android.view.MotionEvent; - -import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.egl.EGLContext; -import javax.microedition.khronos.egl.EGLDisplay; import javax.microedition.khronos.opengles.GL10; class GLES3JNIView extends GLSurfaceView { diff --git a/gradle.properties b/gradle.properties index fd5ffa134..88c953cbc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,16 +7,14 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. For more details, visit -# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app's APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn +# Enables parallel execution for decoupled projects +org.gradle.parallel=true +# Enables the configuration cache for faster builds +org.gradle.configuration-cache=true +# Enables project isolation (incubating, but helps catch future issues) +# org.gradle.isolated-projects=true + +# AndroidX package structure android.useAndroidX=true -# Enables namespacing of each library's R class so that its R class includes only the -# resources declared in the library itself and none from the library's dependencies, -# thereby reducing the size of the R class for that library +# Enables namespacing of each library's R class android.nonTransitiveRClass=true -android.nonFinalResIds=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a3b50c7cf..ff953e873 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,26 +1,34 @@ [versions] -agp = "8.13.0" -kotlin = "1.9.0" -kotlinxCoroutines = "1.7.1" +agp = "9.3.0" +kotlin = "2.4.10" +kotlinxCoroutines = "1.11.0" junit = "4.13.2" -junitVersion = "1.2.1" -espressoCore = "3.6.1" -androidxConstraintLayout = "2.1.4" -androidxCore = "1.13.1" -androidxGames = "3.0.5" -androidxJUnitGTest = "1.0.0-alpha02" -appcompat = "1.6.1" -material = "1.12.0" -jetbrainsKotlinJvm = "1.7.21" -oboe = "1.9.0" +junitVersion = "1.3.0" +espressoCore = "3.7.0" +androidxConstraintLayout = "2.2.1" +androidxCore = "1.19.0" +androidxGames = "4.4.2" +androidxJUnitGTest = "1.0.0-alpha03" +appcompat = "1.7.1" +material = "1.14.0" -activityCompose = "1.9.0" -composeBom = "2023.08.00" -coreKtx = "1.13.1" +oboe = "1.10.0" + +# SDK Versions +compileSdk = "37" +targetSdk = "37" +minSdk = "24" +ndk = "28.2.13676358" +cmake = "4.1.2" +javaTarget = "17" + +activityCompose = "1.13.0" +composeBom = "2026.06.01" +coreKtx = "1.19.0" curl = "7.79.1-beta-1" googletest = "1.11.0-beta-1" -jsoncpp = "1.9.5-beta-1" -lifecycleRuntimeKtx = "2.7.0" +jsoncpp = "1.9.6" +lifecycleRuntimeKtx = "2.11.0" openssl = "1.1.1q-beta-1" [libraries] @@ -60,4 +68,5 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } -jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" } +jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fadf71add..0bc3968cc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon May 06 16:21:05 PDT 2024 +#Wed Jul 15 15:13:15 PDT 2026 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/hello-gl2/app/build.gradle b/hello-gl2/app/build.gradle.kts similarity index 52% rename from hello-gl2/app/build.gradle rename to hello-gl2/app/build.gradle.kts index aba5121ae..89eb3a4a0 100644 --- a/hello-gl2/app/build.gradle +++ b/hello-gl2/app/build.gradle.kts @@ -1,31 +1,31 @@ plugins { - id "ndksamples.android.application" + id("ndksamples.android.application") } android { - namespace 'com.android.gl2jni' + namespace = "com.android.gl2jni" defaultConfig { - applicationId 'com.android.gl2jni' + applicationId = "com.android.gl2jni" externalNativeBuild { cmake { // Available arguments are inside ${SDK}/cmake/.../android.toolchain.cmake file - arguments '-DANDROID_STL=c++_static' + arguments.add("-DANDROID_STL=c++_static") } } } externalNativeBuild { cmake { - path 'src/main/cpp/CMakeLists.txt' + path = file("src/main/cpp/CMakeLists.txt") } } buildFeatures { - prefab true + prefab = true } } dependencies { - implementation project(":base") + implementation(project(":base")) } diff --git a/hello-gl2/app/src/main/cpp/CMakeLists.txt b/hello-gl2/app/src/main/cpp/CMakeLists.txt index 2c35051d9..d4b3ff506 100644 --- a/hello-gl2/app/src/main/cpp/CMakeLists.txt +++ b/hello-gl2/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(HelloGl2 LANGUAGES CXX) include(AppLibrary) diff --git a/hello-gl2/app/src/main/cpp/gl_code.cpp b/hello-gl2/app/src/main/cpp/gl_code.cpp index 9b6946057..997f48b01 100644 --- a/hello-gl2/app/src/main/cpp/gl_code.cpp +++ b/hello-gl2/app/src/main/cpp/gl_code.cpp @@ -21,9 +21,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #define LOG_TAG "libgl2jni" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) diff --git a/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIActivity.java b/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIActivity.java index c366a2cbc..7d8e54680 100644 --- a/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIActivity.java +++ b/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIActivity.java @@ -18,10 +18,6 @@ import android.app.Activity; import android.os.Bundle; -import android.util.Log; -import android.view.WindowManager; - -import java.io.File; public class GL2JNIActivity extends Activity { diff --git a/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIView.java b/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIView.java index 060290a76..9e6c6df68 100644 --- a/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIView.java +++ b/hello-gl2/app/src/main/java/com/android/gl2jni/GL2JNIView.java @@ -35,11 +35,7 @@ import android.content.Context; import android.graphics.PixelFormat; import android.opengl.GLSurfaceView; -import android.util.AttributeSet; import android.util.Log; -import android.view.KeyEvent; -import android.view.MotionEvent; - import javax.microedition.khronos.egl.EGL10; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.egl.EGLContext; diff --git a/hello-jni/app/build.gradle b/hello-jni/app/build.gradle deleted file mode 100644 index cf1a1c8ab..000000000 --- a/hello-jni/app/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -plugins { - id "ndksamples.android.application" - id "ndksamples.android.kotlin" -} - -android { - namespace 'com.example.hellojni' - - defaultConfig { - applicationId 'com.example.hellojni' - versionCode 1 - versionName "1.0" - } - - externalNativeBuild { - cmake { - path "src/main/cpp/CMakeLists.txt" - } - } - - buildFeatures { - viewBinding true - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/hello-jni/app/build.gradle.kts b/hello-jni/app/build.gradle.kts new file mode 100644 index 000000000..9b98861c7 --- /dev/null +++ b/hello-jni/app/build.gradle.kts @@ -0,0 +1,31 @@ +plugins { + id("ndksamples.android.application") + id("ndksamples.android.kotlin") +} + +android { + namespace = "com.example.hellojni" + + defaultConfig { + applicationId = "com.example.hellojni" + versionCode = 1 + versionName = "1.0" + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + viewBinding = true + prefab = true + } +} + +dependencies { + implementation(project(":base")) + implementation(libs.appcompat) + implementation(libs.androidx.constraintlayout) +} diff --git a/hello-jni/app/src/main/cpp/CMakeLists.txt b/hello-jni/app/src/main/cpp/CMakeLists.txt index b165c1a91..2a469fc8c 100644 --- a/hello-jni/app/src/main/cpp/CMakeLists.txt +++ b/hello-jni/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project("hello-jni" LANGUAGES CXX) include(AppLibrary) diff --git a/hello-jniCallback/app/build.gradle b/hello-jniCallback/app/build.gradle deleted file mode 100644 index 5434373c0..000000000 --- a/hello-jniCallback/app/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.example.hellojnicallback' - - defaultConfig { - applicationId 'com.example.hellojnicallback' - versionCode 1 - versionName "1.0" - } - - externalNativeBuild { - cmake { - path "src/main/cpp/CMakeLists.txt" - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/hello-jniCallback/app/build.gradle.kts b/hello-jniCallback/app/build.gradle.kts new file mode 100644 index 000000000..67bb3e404 --- /dev/null +++ b/hello-jniCallback/app/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.example.hellojnicallback" + + defaultConfig { + applicationId = "com.example.hellojnicallback" + versionCode = 1 + versionName = "1.0" + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + } +} + +dependencies { + implementation(project(":base")) + implementation(libs.appcompat) + implementation(libs.androidx.constraintlayout) +} diff --git a/hello-jniCallback/app/src/main/cpp/CMakeLists.txt b/hello-jniCallback/app/src/main/cpp/CMakeLists.txt index ff40da7d9..fee120e7a 100644 --- a/hello-jniCallback/app/src/main/cpp/CMakeLists.txt +++ b/hello-jniCallback/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(HelloJniCallback LANGUAGES CXX) include(AppLibrary) diff --git a/hello-jniCallback/app/src/main/cpp/hello-jnicallback.cpp b/hello-jniCallback/app/src/main/cpp/hello-jnicallback.cpp index 1cd16cb8f..d5625a54d 100644 --- a/hello-jniCallback/app/src/main/cpp/hello-jnicallback.cpp +++ b/hello-jniCallback/app/src/main/cpp/hello-jnicallback.cpp @@ -15,12 +15,12 @@ * */ #include -#include +#include #include -#include +#include #include #include -#include +#include // Android log function wrappers static const char* kTAG = "hello-jniCallback"; diff --git a/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/JniHandler.java b/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/JniHandler.java index 983c1d7af..eda1ed0b4 100644 --- a/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/JniHandler.java +++ b/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/JniHandler.java @@ -17,8 +17,8 @@ package com.example.hellojnicallback; import android.os.Build; -import androidx.annotation.Keep; import android.util.Log; +import androidx.annotation.Keep; /* * A helper class to demo that JNI could call into: diff --git a/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/MainActivity.java b/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/MainActivity.java index cff89cb39..54129df0f 100644 --- a/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/MainActivity.java +++ b/hello-jniCallback/app/src/main/java/com/example/hellojnicallback/MainActivity.java @@ -15,10 +15,10 @@ */ package com.example.hellojnicallback; -import androidx.annotation.Keep; -import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; +import androidx.annotation.Keep; +import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { diff --git a/hello-vulkan/app/build.gradle b/hello-vulkan/app/build.gradle.kts similarity index 71% rename from hello-vulkan/app/build.gradle rename to hello-vulkan/app/build.gradle.kts index 36e43b412..73eb67649 100644 --- a/hello-vulkan/app/build.gradle +++ b/hello-vulkan/app/build.gradle.kts @@ -15,25 +15,25 @@ */ plugins { - id "ndksamples.android.application" - id "ndksamples.android.kotlin" + id("ndksamples.android.application") + id("ndksamples.android.kotlin") } android { - namespace 'com.android.hellovk' + namespace = "com.android.hellovk" defaultConfig { - applicationId 'com.android.hellovk' + applicationId = "com.android.hellovk" // TODO: Figure out why this isn't 24. - minSdk 30 + minSdk = 30 externalNativeBuild { cmake { // Available arguments are inside ${SDK}/cmake/.../android.toolchain.cmake file - arguments "-DANDROID_STL=c++_shared" + arguments.add("-DANDROID_STL=c++_shared") } } shaders { - glslcArgs.addAll(['-c']) + glslcArgs.addAll(listOf("-c")) } ndk { // GameActivity doesn't currently (August 2025) include riscv64 @@ -44,17 +44,17 @@ android { externalNativeBuild { cmake { - path 'src/main/cpp/CMakeLists.txt' + path = file("src/main/cpp/CMakeLists.txt") } } buildFeatures { - prefab true - shaders true + prefab = true + shaders = true } } dependencies { - implementation libs.appcompat - implementation libs.androidx.games.gameactivity + implementation(libs.appcompat) + implementation(libs.androidx.games.gameactivity) } diff --git a/hello-vulkan/app/src/main/cpp/hellovk.h b/hello-vulkan/app/src/main/cpp/hellovk.h index 334fe2406..f72613db1 100644 --- a/hello-vulkan/app/src/main/cpp/hellovk.h +++ b/hello-vulkan/app/src/main/cpp/hellovk.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/hello-vulkan/app/src/main/java/com/android/hellovk/VulkanActivity.kt b/hello-vulkan/app/src/main/java/com/android/hellovk/VulkanActivity.kt index ece0a3e18..7de3a3ddd 100644 --- a/hello-vulkan/app/src/main/java/com/android/hellovk/VulkanActivity.kt +++ b/hello-vulkan/app/src/main/java/com/android/hellovk/VulkanActivity.kt @@ -20,9 +20,9 @@ import android.annotation.SuppressLint import android.os.Build.VERSION import android.os.Build.VERSION_CODES import android.os.Bundle -import android.view.KeyEvent import android.view.View import android.view.WindowManager.LayoutParams +import androidx.activity.OnBackPressedCallback import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat import com.google.androidgamesdk.GameActivity @@ -32,13 +32,19 @@ class VulkanActivity : GameActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) hideSystemUI() + + onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + finishAndRemoveTask() + } + }) } private fun hideSystemUI() { // This will put the game behind any cutouts and waterfalls on devices which have // them, so the corresponding insets will be non-zero. - // We cannot guarantee that AndroidManifest won't be tweaked + // We cannot guarantee that AndroidManifest won't be tweaked, // and we don't want to crash if that happens so we suppress warning. @SuppressLint("ObsoleteSdkInt") if (VERSION.SDK_INT >= VERSION_CODES.P) { @@ -56,29 +62,9 @@ class VulkanActivity : GameActivity() { WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE } - // Filter out back button press, and handle it here after native - // side done its processing. Application can also make a reverse JNI - // call to onBackPressed()/finish() at the end of the KEYCODE_BACK - // processing. - override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { - var processed = super.onKeyDown(keyCode, event); - if (keyCode == KeyEvent.KEYCODE_BACK) { - onBackPressed() - processed = true - } - return processed - } - - // TODO: Migrate to androidx.activity.OnBackPressedCallback. - // onBackPressed is deprecated. - override fun onBackPressed() { - System.gc() - System.exit(0) - } - companion object { init { System.loadLibrary("hellovkjni") } } -} \ No newline at end of file +} diff --git a/native-activity/app/build.gradle b/native-activity/app/build.gradle deleted file mode 100644 index 103c2fb81..000000000 --- a/native-activity/app/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -// Caution: If you add any Java or Kotlin code to this project, or if you add -// any dependencies which themselves use Java/Kotlin, you'll need to remove -// `android:hasCode` from main/AndroidManifest.xml. - -android { - namespace 'com.example.native_activity' - - defaultConfig { - applicationId = 'com.example.native_activity' - // This is the minimum required for using Choreographer directly from the NDK. If you need - // to use a lower minSdkVersion, you must use the Java Choreographer API via JNI. - minSdkVersion 24 - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } -} diff --git a/native-activity/app/build.gradle.kts b/native-activity/app/build.gradle.kts new file mode 100644 index 000000000..3ba177f6d --- /dev/null +++ b/native-activity/app/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + id("ndksamples.android.application") +} + +// Caution: If you add any Java or Kotlin code to this project, or if you add +// any dependencies which themselves use Java/Kotlin, you'll need to remove +// `android:hasCode` from main/AndroidManifest.xml. + +android { + namespace = "com.example.native_activity" + + defaultConfig { + applicationId = "com.example.native_activity" + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } +} diff --git a/native-audio/app/build.gradle b/native-audio/app/build.gradle.kts similarity index 50% rename from native-audio/app/build.gradle rename to native-audio/app/build.gradle.kts index 8ff93538e..fa191b48a 100644 --- a/native-audio/app/build.gradle +++ b/native-audio/app/build.gradle.kts @@ -1,19 +1,18 @@ plugins { - id "ndksamples.android.application" + id("ndksamples.android.application") } android { - namespace 'com.example.nativeaudio' + namespace = "com.example.nativeaudio" defaultConfig { - applicationId 'com.example.nativeaudio' - minSdkVersion 23 + applicationId = "com.example.nativeaudio" } externalNativeBuild { cmake { // todo: need to disable REVERT for fast audio recording - path 'src/main/cpp/CMakeLists.txt' + path = file("src/main/cpp/CMakeLists.txt") } } @@ -24,6 +23,6 @@ android { } dependencies { - implementation project(":base") - implementation libs.appcompat + implementation(project(":base")) + implementation(libs.appcompat) } diff --git a/native-audio/app/src/main/cpp/CMakeLists.txt b/native-audio/app/src/main/cpp/CMakeLists.txt index 9e6ad3bea..7989f3f13 100644 --- a/native-audio/app/src/main/cpp/CMakeLists.txt +++ b/native-audio/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(NativeAudio LANGUAGES CXX) include(AppLibrary) diff --git a/native-audio/app/src/main/cpp/native-audio-jni.cpp b/native-audio/app/src/main/cpp/native-audio-jni.cpp index fad1e37a7..a50ffd487 100644 --- a/native-audio/app/src/main/cpp/native-audio-jni.cpp +++ b/native-audio/app/src/main/cpp/native-audio-jni.cpp @@ -21,12 +21,12 @@ * src/com/example/nativeaudio/NativeAudio/NativeAudio.java */ -#include +#include #include #include #include -#include -#include +#include +#include // for __android_log_print(ANDROID_LOG_INFO, "YourApp", "formatted message"); // #include diff --git a/native-audio/app/src/main/java/com/example/nativeaudio/NativeAudio.java b/native-audio/app/src/main/java/com/example/nativeaudio/NativeAudio.java index 073155458..5734dea24 100644 --- a/native-audio/app/src/main/java/com/example/nativeaudio/NativeAudio.java +++ b/native-audio/app/src/main/java/com/example/nativeaudio/NativeAudio.java @@ -17,16 +17,13 @@ package com.example.nativeaudio; import android.Manifest; -import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.media.AudioManager; -import android.os.Build; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.core.app.ActivityCompat; +import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; @@ -37,6 +34,9 @@ import android.widget.Spinner; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; + public class NativeAudio extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback { @@ -60,7 +60,6 @@ public class NativeAudio extends Activity /** Called when the activity is first created. */ @Override - @TargetApi(17) protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); @@ -78,12 +77,24 @@ protected void onCreate(Bundle icicle) { * IF we do not have a fast audio path, we pass 0 for sampleRate, which will force native * side to pick up the 8Khz sample rate. */ - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); - String nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); - sampleRate = Integer.parseInt(nativeParam); - nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); - bufSize = Integer.parseInt(nativeParam); + AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); + if (myAudioMgr != null) { + String sampleRateStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); + if (sampleRateStr != null) { + try { + sampleRate = Integer.parseInt(sampleRateStr); + } catch (NumberFormatException e) { + Log.e("NativeAudio", "sampleRate failed.", e); + } + } + String bufSizeStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); + if (bufSizeStr != null) { + try { + bufSize = Integer.parseInt(bufSizeStr); + } catch (NumberFormatException e) { + Log.e("NativeAudio", "buffer size failed.", e); + } + } } createBufferQueueAudioPlayer(sampleRate, bufSize); @@ -275,17 +286,15 @@ public void onStopTrackingTouch(SeekBar seekBar) { setStereoPositionUriAudioPlayer(permille); } }); - if (Build.VERSION.SDK_INT > 19) { - int[] uriIds = { R.id.uri_soundtrack, R.id.pause_uri, - R.id.play_uri, R.id.loop_uri, - R.id.mute_left_uri, R.id.mute_right_uri, - R.id.solo_left_uri, R.id.solo_right_uri, - R.id.mute_uri, R.id.enable_stereo_position_uri, - R.id.channels_uri, R.id.volume_uri, - R.id.pan_uri, R.id.uri_spinner,}; - for(int id : uriIds) - findViewById(id).setEnabled(false); - } + int[] uriIds = {R.id.uri_soundtrack, R.id.pause_uri, + R.id.play_uri, R.id.loop_uri, + R.id.mute_left_uri, R.id.mute_right_uri, + R.id.solo_left_uri, R.id.solo_right_uri, + R.id.mute_uri, R.id.enable_stereo_position_uri, + R.id.channels_uri, R.id.volume_uri, + R.id.pan_uri, R.id.uri_spinner,}; + for(int id : uriIds) + findViewById(id).setEnabled(false); ((Button) findViewById(R.id.record)).setOnClickListener(new OnClickListener() { public void onClick(View view) { @@ -396,7 +405,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis public static native void startRecording(); public static native void shutdown(); - /** Load jni .so on initialization */ + /* Load jni .so on initialization */ static { System.loadLibrary("native-audio-jni"); } diff --git a/native-codec/app/build.gradle b/native-codec/app/build.gradle deleted file mode 100644 index d16d27349..000000000 --- a/native-codec/app/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.example.nativecodec' - - defaultConfig { - applicationId 'com.example.nativecodec' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") -} diff --git a/native-codec/app/build.gradle.kts b/native-codec/app/build.gradle.kts new file mode 100644 index 000000000..656b06455 --- /dev/null +++ b/native-codec/app/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.example.nativecodec" + + defaultConfig { + applicationId = "com.example.nativecodec" + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + } +} + +dependencies { + implementation(project(":base")) +} diff --git a/native-codec/app/src/main/cpp/CMakeLists.txt b/native-codec/app/src/main/cpp/CMakeLists.txt index a5eafea42..5de025ea1 100644 --- a/native-codec/app/src/main/cpp/CMakeLists.txt +++ b/native-codec/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(NativeCodec LANGUAGES CXX) include(AppLibrary) diff --git a/native-codec/app/src/main/cpp/looper.cpp b/native-codec/app/src/main/cpp/looper.cpp index da76cd4e1..30a7b8672 100644 --- a/native-codec/app/src/main/cpp/looper.cpp +++ b/native-codec/app/src/main/cpp/looper.cpp @@ -16,15 +16,15 @@ #include "looper.h" -#include -#include +#include +#include #include #include -#include +#include #include #include -#include -#include +#include +#include #include #include #include diff --git a/native-codec/app/src/main/cpp/native-codec-jni.cpp b/native-codec/app/src/main/cpp/native-codec-jni.cpp index 595dec888..f9cd44406 100644 --- a/native-codec/app/src/main/cpp/native-codec-jni.cpp +++ b/native-codec/app/src/main/cpp/native-codec-jni.cpp @@ -24,13 +24,13 @@ * and explicit handling and recovery for more likely error conditions. */ -#include -#include +#include +#include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/native-codec/app/src/main/java/com/example/nativecodec/MyGLSurfaceView.java b/native-codec/app/src/main/java/com/example/nativecodec/MyGLSurfaceView.java index 47f361cdf..aef8277df 100644 --- a/native-codec/app/src/main/java/com/example/nativecodec/MyGLSurfaceView.java +++ b/native-codec/app/src/main/java/com/example/nativecodec/MyGLSurfaceView.java @@ -16,23 +16,20 @@ package com.example.nativecodec; +import android.content.Context; import android.graphics.SurfaceTexture; +import android.opengl.GLES20; +import android.opengl.GLSurfaceView; +import android.opengl.Matrix; +import android.os.SystemClock; +import android.util.AttributeSet; import android.util.Log; - import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; - import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; -import android.content.Context; -import android.opengl.GLES20; -import android.opengl.GLSurfaceView; -import android.opengl.Matrix; -import android.os.SystemClock; -import android.util.AttributeSet; - public class MyGLSurfaceView extends GLSurfaceView { MyRenderer mRenderer; diff --git a/native-codec/app/src/main/java/com/example/nativecodec/NativeCodec.java b/native-codec/app/src/main/java/com/example/nativecodec/NativeCodec.java index ada6508d0..cad6f8775 100644 --- a/native-codec/app/src/main/java/com/example/nativecodec/NativeCodec.java +++ b/native-codec/app/src/main/java/com/example/nativecodec/NativeCodec.java @@ -33,8 +33,6 @@ import android.widget.RadioButton; import android.widget.Spinner; -import java.io.IOException; - public class NativeCodec extends Activity { static final String TAG = "NativeCodec"; diff --git a/native-midi/app/build.gradle b/native-midi/app/build.gradle deleted file mode 100644 index dc9b621ba..000000000 --- a/native-midi/app/build.gradle +++ /dev/null @@ -1,35 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.example.nativemidi' - - defaultConfig { - applicationId "com.example.nativemidi" - minSdkVersion 29 - versionCode 1 - versionName "1.0" - externalNativeBuild { - cmake { - arguments "-DANDROID_STL=c++_static" - } - } - } - - externalNativeBuild { - cmake { - path "src/main/cpp/CMakeLists.txt" - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/native-midi/app/build.gradle.kts b/native-midi/app/build.gradle.kts new file mode 100644 index 000000000..2669a008c --- /dev/null +++ b/native-midi/app/build.gradle.kts @@ -0,0 +1,36 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.example.nativemidi" + + defaultConfig { + applicationId = "com.example.nativemidi" + versionCode = 1 + versionName = "1.0" + // 'AMidiOutputPort_receive' is unavailable: introduced in Android 29 android + minSdk = 30 + 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(libs.androidx.constraintlayout) +} diff --git a/native-midi/app/src/main/cpp/AppMidiManager.cpp b/native-midi/app/src/main/cpp/AppMidiManager.cpp index 93208c519..49912e5d6 100644 --- a/native-midi/app/src/main/cpp/AppMidiManager.cpp +++ b/native-midi/app/src/main/cpp/AppMidiManager.cpp @@ -14,10 +14,10 @@ * limitations under the License. * */ -#include +#include #include #include -#include +#include #include #include diff --git a/native-midi/app/src/main/cpp/CMakeLists.txt b/native-midi/app/src/main/cpp/CMakeLists.txt index 21f24e51c..ce84dc54a 100644 --- a/native-midi/app/src/main/cpp/CMakeLists.txt +++ b/native-midi/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(native_midi LANGUAGES CXX) include(AppLibrary) diff --git a/native-midi/app/src/main/java/com/example/nativemidi/AppMidiManager.java b/native-midi/app/src/main/java/com/example/nativemidi/AppMidiManager.java index 276e68c6e..f0809da2b 100644 --- a/native-midi/app/src/main/java/com/example/nativemidi/AppMidiManager.java +++ b/native-midi/app/src/main/java/com/example/nativemidi/AppMidiManager.java @@ -19,9 +19,8 @@ import android.media.midi.MidiDevice; import android.media.midi.MidiDeviceInfo; -import android.media.midi.MidiManager; import android.media.midi.MidiInputPort; - +import android.media.midi.MidiManager; import java.util.ArrayList; public class AppMidiManager { diff --git a/native-midi/app/src/main/java/com/example/nativemidi/MainActivity.java b/native-midi/app/src/main/java/com/example/nativemidi/MainActivity.java index 90a3bae4d..5ccc7a10d 100644 --- a/native-midi/app/src/main/java/com/example/nativemidi/MainActivity.java +++ b/native-midi/app/src/main/java/com/example/nativemidi/MainActivity.java @@ -19,14 +19,11 @@ import android.app.Activity; import android.content.Context; - import android.media.midi.MidiDeviceInfo; import android.media.midi.MidiManager; - import android.os.Bundle; - +import android.os.Handler; import android.view.View; - import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; @@ -34,9 +31,6 @@ import android.widget.SeekBar; import android.widget.Spinner; import android.widget.TextView; - -import android.os.Handler; - import java.util.ArrayList; /** @@ -183,29 +177,23 @@ public void onClick(View view) { byte[] keys = {60, 64, 67}; // C Major chord byte[] velocities = {60, 60, 60}; // Middling velocity byte channel = 0; // send on channel 0 - switch (view.getId()) { - case R.id.keyDownBtn: - // Simulate a key-down - mAppMidiManager.sendNoteOn(channel, keys, velocities) ; - break; - - case R.id.keyUpBtn: - // Simulate a key-up (converse of key-down above). - mAppMidiManager.sendNoteOff(channel, keys, velocities) ; - break; - - case R.id.progChangeBtn: { - // Send a MIDI program change message - try { - String progNumStr = mProgNumberEdit.getText().toString(); - int progNum = Integer.parseInt(progNumStr); - - mAppMidiManager.sendProgramChange(channel, (byte)progNum); - } catch (NumberFormatException ex) { - // Maybe let the user know - } + int viewId = view.getId(); + if (viewId == R.id.keyDownBtn) { + // Simulate a key-down + mAppMidiManager.sendNoteOn(channel, keys, velocities); + } else if (viewId == R.id.keyUpBtn) { + // Simulate a key-up (converse of key-down above). + mAppMidiManager.sendNoteOff(channel, keys, velocities); + } else if (viewId == R.id.progChangeBtn) { + // Send a MIDI program change message + try { + String progNumStr = mProgNumberEdit.getText().toString(); + int progNum = Integer.parseInt(progNumStr); + + mAppMidiManager.sendProgramChange(channel, (byte) progNum); + } catch (NumberFormatException ex) { + // Maybe let the user know } - break; } } @@ -214,14 +202,11 @@ public void onClick(View view) { // @Override public void onProgressChanged(SeekBar seekBar, int pos, boolean fromUser) { - switch (seekBar.getId()) { - case R.id.controllerSeekBar: - mAppMidiManager.sendController((byte)0, MidiSpec.MIDICC_MODWHEEL, (byte)pos); - break; - - case R.id.pitchBendSeekBar: - mAppMidiManager.sendPitchBend((byte)0, pos); - break; + int seekBarId = seekBar.getId(); + if (seekBarId == R.id.controllerSeekBar) { + mAppMidiManager.sendController((byte) 0, MidiSpec.MIDICC_MODWHEEL, (byte) pos); + } else if (seekBarId == R.id.pitchBendSeekBar) { + mAppMidiManager.sendPitchBend((byte) 0, pos); } } @@ -236,18 +221,13 @@ public void onStopTrackingTouch(SeekBar seekBar) {} // @Override public void onItemSelected(AdapterView spinner, View view, int position, long id) { - switch (spinner.getId()) { - case R.id.outputDevicesSpinner: { - MidiDeviceListItem listItem = (MidiDeviceListItem) spinner.getItemAtPosition(position); - mAppMidiManager.openReceiveDevice(listItem.getDeviceInfo()); - } - break; - - case R.id.inputDevicesSpinner: { - MidiDeviceListItem listItem = (MidiDeviceListItem)spinner.getItemAtPosition(position); - mAppMidiManager.openSendDevice(listItem.getDeviceInfo()); - } - break; + int spinnerId = spinner.getId(); + if (spinnerId == R.id.outputDevicesSpinner) { + MidiDeviceListItem listItem = (MidiDeviceListItem) spinner.getItemAtPosition(position); + mAppMidiManager.openReceiveDevice(listItem.getDeviceInfo()); + } else if (spinnerId == R.id.inputDevicesSpinner) { + MidiDeviceListItem listItem = (MidiDeviceListItem) spinner.getItemAtPosition(position); + mAppMidiManager.openSendDevice(listItem.getDeviceInfo()); } } diff --git a/orderfile/app/build.gradle b/orderfile/app/build.gradle deleted file mode 100644 index cbefe9c26..000000000 --- a/orderfile/app/build.gradle +++ /dev/null @@ -1,39 +0,0 @@ -plugins { - id "ndksamples.android.application" - id 'ndksamples.android.kotlin' -} - -android { - namespace 'com.example.orderfiledemo' - - defaultConfig { - applicationId "com.example.orderfiledemo" - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - externalNativeBuild { - cmake { - cppFlags '' - } - } - } - - externalNativeBuild { - cmake { - path file('src/main/cpp/CMakeLists.txt') - } - } - - buildFeatures { - prefab true - viewBinding true - } -} - -dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.material - implementation libs.androidx.constraintlayout -} diff --git a/orderfile/app/build.gradle.kts b/orderfile/app/build.gradle.kts new file mode 100644 index 000000000..cb0f508aa --- /dev/null +++ b/orderfile/app/build.gradle.kts @@ -0,0 +1,39 @@ +plugins { + id("ndksamples.android.application") + id("ndksamples.android.kotlin") +} + +android { + namespace = "com.example.orderfiledemo" + + defaultConfig { + applicationId = "com.example.orderfiledemo" + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags("") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + viewBinding = true + } +} + +dependencies { + implementation(project(":base")) + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.androidx.constraintlayout) +} diff --git a/orderfile/app/src/main/cpp/CMakeLists.txt b/orderfile/app/src/main/cpp/CMakeLists.txt index a5d78df48..740fa6543 100644 --- a/orderfile/app/src/main/cpp/CMakeLists.txt +++ b/orderfile/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(OrderfileDemo CXX) include(AppLibrary) diff --git a/orderfile/app/src/main/cpp/orderfile.cpp b/orderfile/app/src/main/cpp/orderfile.cpp index f275dd81d..0a994dbe4 100644 --- a/orderfile/app/src/main/cpp/orderfile.cpp +++ b/orderfile/app/src/main/cpp/orderfile.cpp @@ -1,10 +1,10 @@ #include #include -#include +#include #include #include -#include -#include +#include +#include const char kLogTag[] = "orderfiledemo"; diff --git a/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt b/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt index 2523b6c1b..586dc2209 100644 --- a/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt +++ b/orderfile/app/src/main/java/com/example/orderfiledemo/MainActivity.kt @@ -1,8 +1,8 @@ package com.example.orderfiledemo -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import com.example.orderfiledemo .databinding.ActivityMainBinding +import androidx.appcompat.app.AppCompatActivity +import com.example.orderfiledemo.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { diff --git a/sanitizers/app/build.gradle b/sanitizers/app/build.gradle.kts similarity index 68% rename from sanitizers/app/build.gradle rename to sanitizers/app/build.gradle.kts index 4af668105..c48fa0978 100644 --- a/sanitizers/app/build.gradle +++ b/sanitizers/app/build.gradle.kts @@ -1,21 +1,21 @@ plugins { - id "ndksamples.android.application" - id "ndksamples.android.kotlin" + id("ndksamples.android.application") + id("ndksamples.android.kotlin") } android { - namespace 'com.example.sanitizers' + namespace = "com.example.sanitizers" defaultConfig { - applicationId "com.example.sanitizers" - // If you raise minSdk to 23 or higher, make sure you've read the note - // below about useLegacyPackaging. + applicationId = "com.example.sanitizers" + // Since the project's minSdk is 24, we need to use legacy packaging + // for ASan and HWASan to work. See the notes in the buildTypes block + // below. // - // Note that the hwasan build type will override this. See the + // Note that the hwasan build type will override this. See the // androidComponents stanza below. - minSdk 21 - versionCode 1 - versionName "1.0" + versionCode = 1 + versionName = "1.0" // The sanitizers aren't all mutually compatible, so this sample is // split into a buildType per sanitizer below. For most of those @@ -45,40 +45,40 @@ android { // Now that the defaultConfig abiFilters have been cleared, the // buildType abiFilters will actually have an effect. Enable all ABIs, // since that's what we want for most of the sanitizers. - debug { + getByName("debug") { ndk { - abiFilters( + abiFilters.addAll(listOf( "arm64-v8a", "armeabi-v7a", "riscv64", "x86", "x86_64", - ) + )) } // Allows buildTypes which inherit from debug to match dependencies // with the debug buildType. - matchingFallbacks = ["debug"] + matchingFallbacks += "debug" } - release { + getByName("release") { ndk { - abiFilters( + abiFilters.addAll(listOf( "arm64-v8a", "armeabi-v7a", "riscv64", "x86", "x86_64", - ) + )) } } // HWASan for devices starting from Android 14. Does no longer require a special system image. // See https://developer.android.com/ndk/guides/hwasan. - hwasan { - initWith debug - debuggable true - packagingOptions { + create("hwasan") { + initWith(getByName("debug")) + isDebuggable = true + packaging { jniLibs { // Needed for wrap.sh. useLegacyPackaging = true @@ -86,7 +86,7 @@ android { } externalNativeBuild { cmake { - arguments "-DANDROID_STL=c++_shared", "-DSANITIZE=hwasan" + arguments.addAll(listOf("-DANDROID_STL=c++_shared", "-DSANITIZE=hwasan")) } } ndk { @@ -95,13 +95,13 @@ android { // ABIs, which the hwasan buildType inherits. We only want // arm64-v8a here. abiFilters.clear() - abiFilters "arm64-v8a" + abiFilters += "arm64-v8a" } } - asan { - initWith debug - debuggable true - packagingOptions { + create("asan") { + initWith(getByName("debug")) + isDebuggable = true + packaging { jniLibs { // Without legacy packaging, the Android package manager // will not extract the libraries from the APK, and the app @@ -110,24 +110,23 @@ android { // doesn't work in that configuration, so we need to // opt-out of the new behavior. // - // Note that this won't actually do anything to the sample - // in its default configuration. The sample uses minSdk 21, - // and legacy packaging is the default for all builds below - // minSdk 23. - useLegacyPackaging true + // Note that since the project is at minSdk 24, legacy + // packaging is now required here as the default for + // minSdk 23 and above is to load from the APK. + useLegacyPackaging = true } } externalNativeBuild { cmake { - arguments "-DANDROID_ARM_MODE=arm", "-DANDROID_STL=c++_shared", "-DSANITIZE=asan" + arguments.addAll(listOf("-DANDROID_ARM_MODE=arm", "-DANDROID_STL=c++_shared", "-DSANITIZE=asan")) } } } - ubsan { - initWith debug + create("ubsan") { + initWith(getByName("debug")) externalNativeBuild { cmake { - arguments "-DSANITIZE=ubsan" + arguments.add("-DSANITIZE=ubsan") } } } @@ -135,13 +134,13 @@ android { externalNativeBuild { cmake { - path file('src/main/cpp/CMakeLists.txt') + path = file("src/main/cpp/CMakeLists.txt") } } buildFeatures { - prefab true - viewBinding true + prefab = true + viewBinding = true } androidComponents { @@ -152,8 +151,8 @@ android { } dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.material - implementation libs.androidx.constraintlayout + implementation(project(":base")) + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.androidx.constraintlayout) } diff --git a/sanitizers/app/src/main/cpp/CMakeLists.txt b/sanitizers/app/src/main/cpp/CMakeLists.txt index 7a1d224e2..a301f8411 100644 --- a/sanitizers/app/src/main/cpp/CMakeLists.txt +++ b/sanitizers/app/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(sanitizers LANGUAGES CXX) include(AppLibrary) diff --git a/sanitizers/app/src/main/java/com/example/sanitizers/MainActivity.kt b/sanitizers/app/src/main/java/com/example/sanitizers/MainActivity.kt index b5d4751d6..e7e499287 100644 --- a/sanitizers/app/src/main/java/com/example/sanitizers/MainActivity.kt +++ b/sanitizers/app/src/main/java/com/example/sanitizers/MainActivity.kt @@ -1,8 +1,7 @@ package com.example.sanitizers -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import com.example.sanitizers.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { diff --git a/sensor-graph/accelerometer/build.gradle b/sensor-graph/accelerometer/build.gradle deleted file mode 100644 index b6dae6c6a..000000000 --- a/sensor-graph/accelerometer/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.android.accelerometergraph' - - defaultConfig { - applicationId 'com.android.accelerometergraph' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") -} diff --git a/sensor-graph/accelerometer/build.gradle.kts b/sensor-graph/accelerometer/build.gradle.kts new file mode 100644 index 000000000..20aca53b0 --- /dev/null +++ b/sensor-graph/accelerometer/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.android.accelerometergraph" + + defaultConfig { + applicationId = "com.android.accelerometergraph" + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } + + buildFeatures { + prefab = true + } +} + +dependencies { + implementation(project(":base")) +} diff --git a/sensor-graph/accelerometer/src/main/cpp/CMakeLists.txt b/sensor-graph/accelerometer/src/main/cpp/CMakeLists.txt index c18cc20c2..3fac1393b 100644 --- a/sensor-graph/accelerometer/src/main/cpp/CMakeLists.txt +++ b/sensor-graph/accelerometer/src/main/cpp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(SensorGraph LANGUAGES CXX) include(AppLibrary) diff --git a/settings.gradle b/settings.gradle.kts similarity index 100% rename from settings.gradle rename to settings.gradle.kts diff --git a/teapots/choreographer-30fps/build.gradle b/teapots/choreographer-30fps/build.gradle deleted file mode 100644 index 3cb093a02..000000000 --- a/teapots/choreographer-30fps/build.gradle +++ /dev/null @@ -1,32 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.choreographer' - - defaultConfig { - applicationId 'com.sample.choreographer' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } - - buildFeatures { - prefab true - } -} - -dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/teapots/choreographer-30fps/build.gradle.kts b/teapots/choreographer-30fps/build.gradle.kts new file mode 100644 index 000000000..0bb082de7 --- /dev/null +++ b/teapots/choreographer-30fps/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.sample.choreographer" + + defaultConfig { + applicationId = "com.sample.choreographer" + // 'AImageDecoder' is unavailable: introduced in Android 30 android + minSdk = 30 + 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(libs.androidx.constraintlayout) +} diff --git a/teapots/choreographer-30fps/src/main/cpp/CMakeLists.txt b/teapots/choreographer-30fps/src/main/cpp/CMakeLists.txt index 585f796d5..4ad75c25f 100644 --- a/teapots/choreographer-30fps/src/main/cpp/CMakeLists.txt +++ b/teapots/choreographer-30fps/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(ChoreographerNativeActivity LANGUAGES C CXX) include(AppLibrary) diff --git a/teapots/choreographer-30fps/src/main/cpp/TeapotRenderer.h b/teapots/choreographer-30fps/src/main/cpp/TeapotRenderer.h index 105978a23..cd607a426 100644 --- a/teapots/choreographer-30fps/src/main/cpp/TeapotRenderer.h +++ b/teapots/choreographer-30fps/src/main/cpp/TeapotRenderer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/teapots/choreographer-30fps/src/main/java/com/sample/choreographer/ChoreographerApplication.java b/teapots/choreographer-30fps/src/main/java/com/sample/choreographer/ChoreographerApplication.java index 8988fdb21..fb10ee5fc 100644 --- a/teapots/choreographer-30fps/src/main/java/com/sample/choreographer/ChoreographerApplication.java +++ b/teapots/choreographer-30fps/src/main/java/com/sample/choreographer/ChoreographerApplication.java @@ -16,17 +16,10 @@ package com.sample.choreographer; -import javax.microedition.khronos.opengles.GL10; - import android.app.Application; -import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.opengl.GLUtils; import android.util.Log; import android.widget.Toast; diff --git a/teapots/choreographer-30fps/src/main/java/com/sample/helper/NDKHelper.java b/teapots/choreographer-30fps/src/main/java/com/sample/helper/NDKHelper.java index f89b0d46b..2d7a4ef44 100644 --- a/teapots/choreographer-30fps/src/main/java/com/sample/helper/NDKHelper.java +++ b/teapots/choreographer-30fps/src/main/java/com/sample/helper/NDKHelper.java @@ -16,25 +16,13 @@ package com.sample.helper; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.nio.ByteBuffer; - -import javax.microedition.khronos.opengles.GL10; - -import android.R.bool; -import android.opengl.GLES30; - import android.annotation.TargetApi; -import android.app.Activity; import android.app.NativeActivity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.AudioManager; @@ -42,8 +30,10 @@ import android.opengl.GLUtils; import android.os.Build; import android.util.Log; -import android.view.View; -import android.view.View.MeasureSpec; +import java.io.File; +import java.io.FileInputStream; +import java.nio.ByteBuffer; +import javax.microedition.khronos.opengles.GL10; @TargetApi(Build.VERSION_CODES.GINGERBREAD) public class NDKHelper { @@ -319,7 +309,6 @@ public String getStringResource(String resourceName) // // Audio related helpers // - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public int getNativeAudioBufferSize() { int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 17) { diff --git a/teapots/classic-teapot/build.gradle b/teapots/classic-teapot/build.gradle deleted file mode 100644 index f13cc171b..000000000 --- a/teapots/classic-teapot/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.teapot' - - defaultConfig { - applicationId = 'com.sample.teapot' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } -} - -dependencies { - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/teapots/classic-teapot/build.gradle.kts b/teapots/classic-teapot/build.gradle.kts new file mode 100644 index 000000000..9ae69a86f --- /dev/null +++ b/teapots/classic-teapot/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.sample.teapot" + + defaultConfig { + applicationId = "com.sample.teapot" + // 'AImageDecoder' is unavailable: introduced in Android 30 android + minSdk = 30 + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } +} + +dependencies { + implementation(libs.appcompat) + implementation(libs.androidx.constraintlayout) +} diff --git a/teapots/classic-teapot/src/main/cpp/CMakeLists.txt b/teapots/classic-teapot/src/main/cpp/CMakeLists.txt index da521b243..d4b57dea4 100644 --- a/teapots/classic-teapot/src/main/cpp/CMakeLists.txt +++ b/teapots/classic-teapot/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(TeapotNativeActivity LANGUAGES C CXX) include(AppLibrary) diff --git a/teapots/classic-teapot/src/main/cpp/TeapotNativeActivity.cpp b/teapots/classic-teapot/src/main/cpp/TeapotNativeActivity.cpp index bbdde092e..e4bf8eec4 100644 --- a/teapots/classic-teapot/src/main/cpp/TeapotNativeActivity.cpp +++ b/teapots/classic-teapot/src/main/cpp/TeapotNativeActivity.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "NDKHelper.h" diff --git a/teapots/classic-teapot/src/main/cpp/TeapotRenderer.h b/teapots/classic-teapot/src/main/cpp/TeapotRenderer.h index 9c9aef53b..89ef44090 100644 --- a/teapots/classic-teapot/src/main/cpp/TeapotRenderer.h +++ b/teapots/classic-teapot/src/main/cpp/TeapotRenderer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/teapots/classic-teapot/src/main/java/com/sample/helper/NDKHelper.java b/teapots/classic-teapot/src/main/java/com/sample/helper/NDKHelper.java index f89b0d46b..2b7aa3b18 100644 --- a/teapots/classic-teapot/src/main/java/com/sample/helper/NDKHelper.java +++ b/teapots/classic-teapot/src/main/java/com/sample/helper/NDKHelper.java @@ -16,36 +16,23 @@ package com.sample.helper; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.nio.ByteBuffer; - -import javax.microedition.khronos.opengles.GL10; - -import android.R.bool; -import android.opengl.GLES30; - -import android.annotation.TargetApi; -import android.app.Activity; import android.app.NativeActivity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.AudioManager; import android.media.AudioTrack; import android.opengl.GLUtils; -import android.os.Build; import android.util.Log; -import android.view.View; -import android.view.View.MeasureSpec; +import java.io.File; +import java.io.FileInputStream; +import java.nio.ByteBuffer; +import javax.microedition.khronos.opengles.GL10; -@TargetApi(Build.VERSION_CODES.GINGERBREAD) public class NDKHelper { public NDKHelper(NativeActivity act) { @@ -319,7 +306,6 @@ public String getStringResource(String resourceName) // // Audio related helpers // - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public int getNativeAudioBufferSize() { int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 17) { diff --git a/teapots/classic-teapot/src/main/java/com/sample/teapot/TeapotApplication.java b/teapots/classic-teapot/src/main/java/com/sample/teapot/TeapotApplication.java index 34b4b4d92..53099d94b 100644 --- a/teapots/classic-teapot/src/main/java/com/sample/teapot/TeapotApplication.java +++ b/teapots/classic-teapot/src/main/java/com/sample/teapot/TeapotApplication.java @@ -16,17 +16,10 @@ package com.sample.teapot; -import javax.microedition.khronos.opengles.GL10; - import android.app.Application; -import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.opengl.GLUtils; import android.util.Log; import android.widget.Toast; diff --git a/teapots/common/ndk_helper/CMakeLists.txt b/teapots/common/ndk_helper/CMakeLists.txt index 2717cd6e0..ed1399500 100644 --- a/teapots/common/ndk_helper/CMakeLists.txt +++ b/teapots/common/ndk_helper/CMakeLists.txt @@ -1,5 +1,5 @@ # build native_app_glue as a static lib -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) include(AndroidNdkModules) include(AppLibrary) diff --git a/teapots/image-decoder/build.gradle b/teapots/image-decoder/build.gradle deleted file mode 100644 index d353db533..000000000 --- a/teapots/image-decoder/build.gradle +++ /dev/null @@ -1,28 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.imagedecoder' - - defaultConfig { - applicationId = 'com.sample.imagedecoder' - minSdkVersion 30 - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } -} - -dependencies { - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/teapots/image-decoder/build.gradle.kts b/teapots/image-decoder/build.gradle.kts new file mode 100644 index 000000000..221937c1c --- /dev/null +++ b/teapots/image-decoder/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.sample.imagedecoder" + + defaultConfig { + applicationId = "com.sample.imagedecoder" + // 'AImageDecoder' is unavailable: introduced in Android 30 android + minSdk = 30 + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } +} + +dependencies { + implementation(libs.appcompat) + implementation(libs.androidx.constraintlayout) +} diff --git a/teapots/image-decoder/src/main/cpp/CMakeLists.txt b/teapots/image-decoder/src/main/cpp/CMakeLists.txt index 23b797e47..b5ea4ef76 100644 --- a/teapots/image-decoder/src/main/cpp/CMakeLists.txt +++ b/teapots/image-decoder/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(ImageDecoderNativeActivity LANGUAGES C CXX) include(AppLibrary) diff --git a/teapots/image-decoder/src/main/cpp/TeapotNativeActivity.cpp b/teapots/image-decoder/src/main/cpp/TeapotNativeActivity.cpp index 575611057..3048e8a69 100644 --- a/teapots/image-decoder/src/main/cpp/TeapotNativeActivity.cpp +++ b/teapots/image-decoder/src/main/cpp/TeapotNativeActivity.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "ImageDecoderRender.h" diff --git a/teapots/image-decoder/src/main/cpp/TeapotRenderer.h b/teapots/image-decoder/src/main/cpp/TeapotRenderer.h index a4fda7ae5..f1b840ba1 100644 --- a/teapots/image-decoder/src/main/cpp/TeapotRenderer.h +++ b/teapots/image-decoder/src/main/cpp/TeapotRenderer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/teapots/image-decoder/src/main/cpp/Texture.cpp b/teapots/image-decoder/src/main/cpp/Texture.cpp index 4975479d4..6c0e9d004 100644 --- a/teapots/image-decoder/src/main/cpp/Texture.cpp +++ b/teapots/image-decoder/src/main/cpp/Texture.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #define MODULE_NAME "Teapot::Texture" #include "android_debug.h" diff --git a/teapots/image-decoder/src/main/java/com/sample/helper/NDKHelper.java b/teapots/image-decoder/src/main/java/com/sample/helper/NDKHelper.java index f89b0d46b..8d56ebb1f 100644 --- a/teapots/image-decoder/src/main/java/com/sample/helper/NDKHelper.java +++ b/teapots/image-decoder/src/main/java/com/sample/helper/NDKHelper.java @@ -16,25 +16,12 @@ package com.sample.helper; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.nio.ByteBuffer; - -import javax.microedition.khronos.opengles.GL10; - -import android.R.bool; -import android.opengl.GLES30; - -import android.annotation.TargetApi; -import android.app.Activity; import android.app.NativeActivity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.AudioManager; @@ -42,10 +29,11 @@ import android.opengl.GLUtils; import android.os.Build; import android.util.Log; -import android.view.View; -import android.view.View.MeasureSpec; +import java.io.File; +import java.io.FileInputStream; +import java.nio.ByteBuffer; +import javax.microedition.khronos.opengles.GL10; -@TargetApi(Build.VERSION_CODES.GINGERBREAD) public class NDKHelper { public NDKHelper(NativeActivity act) { @@ -107,7 +95,7 @@ private Bitmap scaleBitmap(Bitmap bitmapToScale, float newWidth, true); } - public class TextureInformation { + public static class TextureInformation { boolean ret; boolean alphaChannel; int originalWidth; @@ -319,7 +307,6 @@ public String getStringResource(String resourceName) // // Audio related helpers // - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public int getNativeAudioBufferSize() { int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 17) { diff --git a/teapots/image-decoder/src/main/java/com/sample/imagedecoder/TeapotApplication.java b/teapots/image-decoder/src/main/java/com/sample/imagedecoder/TeapotApplication.java index 58b7d85f6..357b51e93 100644 --- a/teapots/image-decoder/src/main/java/com/sample/imagedecoder/TeapotApplication.java +++ b/teapots/image-decoder/src/main/java/com/sample/imagedecoder/TeapotApplication.java @@ -16,17 +16,10 @@ package com.sample.imagedecoder; -import javax.microedition.khronos.opengles.GL10; - import android.app.Application; -import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.opengl.GLUtils; import android.util.Log; import android.widget.Toast; diff --git a/teapots/more-teapots/build.gradle b/teapots/more-teapots/build.gradle deleted file mode 100644 index 2d22a2504..000000000 --- a/teapots/more-teapots/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.moreteapots' - - defaultConfig { - applicationId 'com.sample.moreteapots' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } -} -dependencies { - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/teapots/more-teapots/build.gradle.kts b/teapots/more-teapots/build.gradle.kts new file mode 100644 index 000000000..c28b171e1 --- /dev/null +++ b/teapots/more-teapots/build.gradle.kts @@ -0,0 +1,28 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.sample.moreteapots" + + defaultConfig { + applicationId = "com.sample.moreteapots" + // 'AImageDecoder' is unavailable: introduced in Android 30 android + minSdk = 30 + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } +} +dependencies { + implementation(libs.appcompat) + implementation(libs.androidx.constraintlayout) +} diff --git a/teapots/more-teapots/src/main/cpp/CMakeLists.txt b/teapots/more-teapots/src/main/cpp/CMakeLists.txt index cd0ad6e61..21e0f95ea 100644 --- a/teapots/more-teapots/src/main/cpp/CMakeLists.txt +++ b/teapots/more-teapots/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(MoreTeapotsNativeActivity LANGUAGES C CXX) include(AppLibrary) diff --git a/teapots/more-teapots/src/main/cpp/MoreTeapotsNativeActivity.cpp b/teapots/more-teapots/src/main/cpp/MoreTeapotsNativeActivity.cpp index 502d07b1f..b3efba15e 100644 --- a/teapots/more-teapots/src/main/cpp/MoreTeapotsNativeActivity.cpp +++ b/teapots/more-teapots/src/main/cpp/MoreTeapotsNativeActivity.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include diff --git a/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.cpp b/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.cpp index 352b3dba8..3ca725971 100644 --- a/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.cpp +++ b/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.cpp @@ -23,7 +23,7 @@ //-------------------------------------------------------------------------------- #include "MoreTeapotsRenderer.h" -#include +#include #include diff --git a/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.h b/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.h index 7201f5783..de758df24 100644 --- a/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.h +++ b/teapots/more-teapots/src/main/cpp/MoreTeapotsRenderer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/teapots/more-teapots/src/main/java/com/sample/helper/NDKHelper.java b/teapots/more-teapots/src/main/java/com/sample/helper/NDKHelper.java index f89b0d46b..2d7a4ef44 100644 --- a/teapots/more-teapots/src/main/java/com/sample/helper/NDKHelper.java +++ b/teapots/more-teapots/src/main/java/com/sample/helper/NDKHelper.java @@ -16,25 +16,13 @@ package com.sample.helper; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.nio.ByteBuffer; - -import javax.microedition.khronos.opengles.GL10; - -import android.R.bool; -import android.opengl.GLES30; - import android.annotation.TargetApi; -import android.app.Activity; import android.app.NativeActivity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.AudioManager; @@ -42,8 +30,10 @@ import android.opengl.GLUtils; import android.os.Build; import android.util.Log; -import android.view.View; -import android.view.View.MeasureSpec; +import java.io.File; +import java.io.FileInputStream; +import java.nio.ByteBuffer; +import javax.microedition.khronos.opengles.GL10; @TargetApi(Build.VERSION_CODES.GINGERBREAD) public class NDKHelper { @@ -319,7 +309,6 @@ public String getStringResource(String resourceName) // // Audio related helpers // - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public int getNativeAudioBufferSize() { int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 17) { diff --git a/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsApplication.java b/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsApplication.java index c0bf2cecc..e8048d61f 100644 --- a/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsApplication.java +++ b/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsApplication.java @@ -16,19 +16,11 @@ package com.sample.moreteapots; -import javax.microedition.khronos.opengles.GL10; - -import com.sample.helper.NDKHelper; - import android.app.Application; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.opengl.GLUtils; import android.util.Log; import android.widget.Toast; diff --git a/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsNativeActivity.java b/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsNativeActivity.java index 04e53e13f..2a70f57e5 100644 --- a/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsNativeActivity.java +++ b/teapots/more-teapots/src/main/java/com/sample/moreteapots/MoreTeapotsNativeActivity.java @@ -19,7 +19,6 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.NativeActivity; -import android.content.res.Configuration; import android.os.Bundle; import android.util.Log; import android.view.Gravity; diff --git a/teapots/textured-teapot/build.gradle b/teapots/textured-teapot/build.gradle deleted file mode 100644 index 86dda65dc..000000000 --- a/teapots/textured-teapot/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - id "ndksamples.android.application" -} - -android { - namespace 'com.sample.texturedteapot' - - defaultConfig { - applicationId = 'com.sample.texturedteapot' - externalNativeBuild { - cmake { - arguments '-DANDROID_STL=c++_static' - } - } - } - - externalNativeBuild { - cmake { - path 'src/main/cpp/CMakeLists.txt' - } - } -} - -dependencies { - implementation libs.appcompat - implementation libs.androidx.constraintlayout -} diff --git a/teapots/textured-teapot/build.gradle.kts b/teapots/textured-teapot/build.gradle.kts new file mode 100644 index 000000000..b1a78fccd --- /dev/null +++ b/teapots/textured-teapot/build.gradle.kts @@ -0,0 +1,29 @@ +plugins { + id("ndksamples.android.application") +} + +android { + namespace = "com.sample.texturedteapot" + + defaultConfig { + applicationId = "com.sample.texturedteapot" + // 'AImageDecoder' is unavailable: introduced in Android 30 android + minSdk = 30 + externalNativeBuild { + cmake { + arguments.add("-DANDROID_STL=c++_static") + } + } + } + + externalNativeBuild { + cmake { + path = file("src/main/cpp/CMakeLists.txt") + } + } +} + +dependencies { + implementation(libs.appcompat) + implementation(libs.androidx.constraintlayout) +} diff --git a/teapots/textured-teapot/src/main/cpp/CMakeLists.txt b/teapots/textured-teapot/src/main/cpp/CMakeLists.txt index 2aa3f57e0..812594730 100644 --- a/teapots/textured-teapot/src/main/cpp/CMakeLists.txt +++ b/teapots/textured-teapot/src/main/cpp/CMakeLists.txt @@ -14,7 +14,7 @@ # limitations under the License. # -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project(TexturedTeapotNativeActivity LANGUAGES C CXX) include(AppLibrary) diff --git a/teapots/textured-teapot/src/main/cpp/TeapotNativeActivity.cpp b/teapots/textured-teapot/src/main/cpp/TeapotNativeActivity.cpp index 8b6ed8c0a..049b133d5 100644 --- a/teapots/textured-teapot/src/main/cpp/TeapotNativeActivity.cpp +++ b/teapots/textured-teapot/src/main/cpp/TeapotNativeActivity.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "NDKHelper.h" diff --git a/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h b/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h index 0f051eeb4..f41769354 100644 --- a/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h +++ b/teapots/textured-teapot/src/main/cpp/TeapotRenderer.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/teapots/textured-teapot/src/main/java/com/sample/helper/NDKHelper.java b/teapots/textured-teapot/src/main/java/com/sample/helper/NDKHelper.java index f89b0d46b..2d7a4ef44 100644 --- a/teapots/textured-teapot/src/main/java/com/sample/helper/NDKHelper.java +++ b/teapots/textured-teapot/src/main/java/com/sample/helper/NDKHelper.java @@ -16,25 +16,13 @@ package com.sample.helper; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.nio.ByteBuffer; - -import javax.microedition.khronos.opengles.GL10; - -import android.R.bool; -import android.opengl.GLES30; - import android.annotation.TargetApi; -import android.app.Activity; import android.app.NativeActivity; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.Bitmap; -import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.AudioManager; @@ -42,8 +30,10 @@ import android.opengl.GLUtils; import android.os.Build; import android.util.Log; -import android.view.View; -import android.view.View.MeasureSpec; +import java.io.File; +import java.io.FileInputStream; +import java.nio.ByteBuffer; +import javax.microedition.khronos.opengles.GL10; @TargetApi(Build.VERSION_CODES.GINGERBREAD) public class NDKHelper { @@ -319,7 +309,6 @@ public String getStringResource(String resourceName) // // Audio related helpers // - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public int getNativeAudioBufferSize() { int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT >= 17) { diff --git a/teapots/textured-teapot/src/main/java/com/sample/texturedteapot/TeapotApplication.java b/teapots/textured-teapot/src/main/java/com/sample/texturedteapot/TeapotApplication.java index 2b9a08ee0..7f8c1ee49 100644 --- a/teapots/textured-teapot/src/main/java/com/sample/texturedteapot/TeapotApplication.java +++ b/teapots/textured-teapot/src/main/java/com/sample/texturedteapot/TeapotApplication.java @@ -16,17 +16,10 @@ package com.sample.texturedteapot; -import javax.microedition.khronos.opengles.GL10; - import android.app.Application; -import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Matrix; -import android.opengl.GLUtils; import android.util.Log; import android.widget.Toast; diff --git a/unit-test/app/build.gradle b/unit-test/app/build.gradle.kts similarity index 50% rename from unit-test/app/build.gradle rename to unit-test/app/build.gradle.kts index 988581996..667cdfdb0 100644 --- a/unit-test/app/build.gradle +++ b/unit-test/app/build.gradle.kts @@ -1,17 +1,17 @@ plugins { - id "ndksamples.android.application" - id "ndksamples.android.kotlin" + id("ndksamples.android.application") + id("ndksamples.android.kotlin") } android { - namespace 'com.example.unittest' + namespace = "com.example.unittest" defaultConfig { - applicationId "com.example.unittest" - versionCode 1 - versionName "1.0" + applicationId = "com.example.unittest" + versionCode = 1 + versionName = "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" ndk { // junit-gtest and googletest don't currently (August 2025) include @@ -22,16 +22,16 @@ android { externalNativeBuild { cmake { - path file('src/main/cpp/CMakeLists.txt') + path = file("src/main/cpp/CMakeLists.txt") } } buildFeatures { - viewBinding true - prefab true + viewBinding = true + prefab = true } - packagingOptions { + packaging { jniLibs { // Gradle has no way of knowing which of the libraries in our // CMakeLists.txt are for the app and which are for tests, so we @@ -41,19 +41,19 @@ android { // // If you copy this project, be sure to update this to specify the // names of your own test libraries. - testOnly += ["**/libapp_tests.so"] + testOnly.add("**/libapp_tests.so") } } } dependencies { - implementation project(":base") - implementation libs.appcompat - implementation libs.material - implementation libs.androidx.constraintlayout - implementation libs.androidx.junit.gtest - implementation libs.googletest - testImplementation libs.junit - androidTestImplementation libs.ext.junit - androidTestImplementation libs.espresso.core -} \ No newline at end of file + implementation(project(":base")) + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.junit.gtest) + implementation(libs.googletest) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) +} diff --git a/unit-test/app/src/main/cpp/CMakeLists.txt b/unit-test/app/src/main/cpp/CMakeLists.txt index 7f0b7f266..d951e7d3a 100644 --- a/unit-test/app/src/main/cpp/CMakeLists.txt +++ b/unit-test/app/src/main/cpp/CMakeLists.txt @@ -3,7 +3,7 @@ # Sets the minimum version of CMake required to build the native library. -cmake_minimum_required(VERSION 3.22.1) +cmake_minimum_required(VERSION 4.1.0) project("unittest") include(AppLibrary) diff --git a/unit-test/app/src/main/java/com/example/unittest/MainActivity.kt b/unit-test/app/src/main/java/com/example/unittest/MainActivity.kt index a0135d0ba..1784edb22 100644 --- a/unit-test/app/src/main/java/com/example/unittest/MainActivity.kt +++ b/unit-test/app/src/main/java/com/example/unittest/MainActivity.kt @@ -1,8 +1,7 @@ package com.example.unittest -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity import com.example.unittest.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { diff --git a/unit-test/app/src/main/res/values-night/themes.xml b/unit-test/app/src/main/res/values-night/themes.xml index 7c99dedcd..7efeeb846 100644 --- a/unit-test/app/src/main/res/values-night/themes.xml +++ b/unit-test/app/src/main/res/values-night/themes.xml @@ -1,4 +1,4 @@ - +