diff --git a/audio-echo/app/src/main/cpp/CMakeLists.txt b/audio-echo/app/src/main/cpp/CMakeLists.txt index afbd8a68f..492586742 100644 --- a/audio-echo/app/src/main/cpp/CMakeLists.txt +++ b/audio-echo/app/src/main/cpp/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22.1) project(echo LANGUAGES C CXX) add_library(echo - SHARED + SHARED audio_main.cpp audio_player.cpp audio_recorder.cpp @@ -12,12 +12,28 @@ add_library(echo #include libraries needed for echo lib target_link_libraries(echo - PRIVATE + PRIVATE OpenSLES android log atomic) target_compile_options(echo - PRIVATE - -Wall -Werror) + PRIVATE + -Wall + -Werror +) + +if (ANDROID_ABI STREQUAL riscv64) + # This sample uses OpenSLES, which was deprecated in API 26. Our + # minSdkVersion is 21, but we also build for riscv64, which isn't a + # supported ABI yet and so that configuration is built for the latest API + # level supported by the NDK. + # + # Longer term, this sample should probably be deleted. App developers + # should be using Oboe rather than OpenSLES, and we already have a separate + # sample for Oboe. There is some potentially useful audio latency + # measurement in this sample that should be moved to the Oboe sample before + # we delete it though. + target_compile_options(echo PRIVATE -Wno-deprecated-declarations) +endif () 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 8305a2a43..6bd96f0c4 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 @@ -32,6 +32,22 @@ class AndroidApplicationConventionPlugin : Plugin { arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON") } } + + ndk { + // riscv64 isn't a supported Android ABI yet (August 2025), but we're + // enabling it here as part of that experiment. Until it's a supported ABI, + // don't include this in your app, as Play will block uploads of APKs which + // contain riscv64 libraries. + abiFilters.addAll( + listOf( + "arm64-v8a", + "armeabi-v7a", + "riscv64", + "x86", + "x86_64", + ) + ) + } } compileOptions { sourceCompatibility = Versions.JAVA 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 24cd93cae..1ac2746d4 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 @@ -35,6 +35,21 @@ class AndroidLibraryConventionPlugin : Plugin { arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON") } } + ndk { + // riscv64 isn't a supported Android ABI yet (August 2025), but we're + // enabling it here as part of that experiment. Until it's a supported ABI, + // don't include this in your app, as Play will block uploads of APKs which + // contain riscv64 libraries. + abiFilters.addAll( + listOf( + "arm64-v8a", + "armeabi-v7a", + "riscv64", + "x86", + "x86_64", + ) + ) + } } compileOptions { sourceCompatibility = Versions.JAVA diff --git a/hello-libs/app/build.gradle b/hello-libs/app/build.gradle index b6911b6dc..cb019575a 100644 --- a/hello-libs/app/build.gradle +++ b/hello-libs/app/build.gradle @@ -14,6 +14,12 @@ android { arguments '-DANDROID_STL=c++_static' } } + + ndk { + // This sample relies on prebuilt libraries, and we haven't built + // rv64 versions of those libraries yet. + abiFilters.remove("riscv64") + } } externalNativeBuild { diff --git a/hello-neon/app/build.gradle b/hello-neon/app/build.gradle index 7bea6a4fc..9a810e17d 100644 --- a/hello-neon/app/build.gradle +++ b/hello-neon/app/build.gradle @@ -4,11 +4,23 @@ plugins { android { namespace 'com.example.helloneon' - + defaultConfig { applicationId "com.example.helloneon" versionCode 1 versionName "1.0" + + ndk { + // rv64 doesn't support Neon intrinsics. You shouldn't really use + // those anyway, since they're just a non-portable wrapper around + // the portable Clang vector intrinsics: + // + // https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors + // + // TODO: Delete this sample in favor of a better one. + // https://github.com/android/ndk-samples/issues/1011 + abiFilters.remove("riscv64") + } } externalNativeBuild { diff --git a/hello-oboe/app/build.gradle b/hello-oboe/app/build.gradle index f86745bde..79d94cd4d 100644 --- a/hello-oboe/app/build.gradle +++ b/hello-oboe/app/build.gradle @@ -5,13 +5,18 @@ plugins { android { namespace 'com.google.example.hellooboe' - + defaultConfig { applicationId "com.google.example.hellooboe" versionCode 1 versionName "1.0" externalNativeBuild.cmake { - arguments "-DANDROID_STL=c++_shared" + arguments "-DANDROID_STL=c++_shared" + } + + ndk { + // Oboe doesn't currently (August 2025) include riscv64 libraries. + abiFilters.remove("riscv64") } } diff --git a/hello-vulkan/app/build.gradle b/hello-vulkan/app/build.gradle index 32e3bcea9..36e43b412 100644 --- a/hello-vulkan/app/build.gradle +++ b/hello-vulkan/app/build.gradle @@ -21,7 +21,7 @@ plugins { android { namespace 'com.android.hellovk' - + defaultConfig { applicationId 'com.android.hellovk' // TODO: Figure out why this isn't 24. @@ -35,6 +35,11 @@ android { shaders { glslcArgs.addAll(['-c']) } + ndk { + // GameActivity doesn't currently (August 2025) include riscv64 + // libraries. + abiFilters.remove("riscv64") + } } externalNativeBuild { diff --git a/native-activity/app/src/main/cpp/CMakeLists.txt b/native-activity/app/src/main/cpp/CMakeLists.txt index 933146c82..f5b1ab7b1 100644 --- a/native-activity/app/src/main/cpp/CMakeLists.txt +++ b/native-activity/app/src/main/cpp/CMakeLists.txt @@ -41,3 +41,16 @@ target_link_libraries(native-activity EGL GLESv1_CM log) + +if (ANDROID_ABI STREQUAL riscv64) + # This sample uses Sensor Manager and Choreographer APIs which are + # deprecated in modern API levels. Our minSdkVersion is 21, but we also + # build for riscv64, which isn't a supported ABI yet and so that + # configuration is built for the latest API level supported by the NDK. + # + # This sample should be tweaked to use the replacement APIs when they're + # available at runtime and only use the older APIs on older devices. For + # now, just disable the deprecation warnings so we can get the riscv64 + # samples building in CI, and we can come back to clean that up later. + target_compile_options(native-activity PRIVATE -Wno-deprecated-declarations) +endif () diff --git a/prefab/curl-ssl/app/build.gradle b/prefab/curl-ssl/app/build.gradle index b6e647422..762e8c25b 100644 --- a/prefab/curl-ssl/app/build.gradle +++ b/prefab/curl-ssl/app/build.gradle @@ -34,6 +34,12 @@ android { } } } + + ndk { + // None of the ndkports libraries currently (August 2025) include + // riscv64 libraries. + abiFilters.remove("riscv64") + } } externalNativeBuild { diff --git a/prefab/prefab-dependency/app/build.gradle b/prefab/prefab-dependency/app/build.gradle index ab7330a6b..9cf40f065 100644 --- a/prefab/prefab-dependency/app/build.gradle +++ b/prefab/prefab-dependency/app/build.gradle @@ -34,6 +34,12 @@ android { } } } + + ndk { + // None of the ndkports libraries currently (August 2025) include + // riscv64 libraries. + abiFilters.remove("riscv64") + } } externalNativeBuild { diff --git a/sanitizers/app/build.gradle b/sanitizers/app/build.gradle index 176871c60..00d696db3 100644 --- a/sanitizers/app/build.gradle +++ b/sanitizers/app/build.gradle @@ -16,9 +16,59 @@ android { minSdk 21 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 + // sanitizers, we support every ABI. The HWASan buildType is the + // exception, where we want to enable only arm64-v8a. + // + // Unfortunately, the convention plugin enables every ABI using + // defaultConfig.ndk.abiFilters, which apparently overrides anything we + // do in buildTypes. To be able to control which ABIs get built here + // using buildTypes, we have to undo the work done by the convention + // plugin by clearing the defaultConfig abiFilters. Instead, we enable + // all the ABIs in the debug and release buildTypes below, inherit from + // those for most of the sanitizers, but then again reset the list for + // HWASan to enable only arm64-v8a. + // + // We could instead change the convention plugin to use buildType + // instead, but then all the samples that need to disable rv64 would + // have to do it twice (once for release and once for debug). Since the + // sanitizers sample is the only one that needs this behavior, I'd + // rather keep the mess here rather than spread it around. + ndk { + abiFilters.clear() + } } buildTypes { + // 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 { + ndk { + abiFilters( + "arm64-v8a", + "armeabi-v7a", + "riscv64", + "x86", + "x86_64", + ) + } + } + + release { + ndk { + abiFilters( + "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 { @@ -36,6 +86,11 @@ android { } } ndk { + // The defaultConfig's abiFilters were cleared above, but then + // we also populated the debug buildType's abiFilters with all + // ABIs, which the hwasan buildType inherits. We only want + // arm64-v8a here. + abiFilters.clear() abiFilters "arm64-v8a" } } diff --git a/sanitizers/app/src/ubsan/jniLibs/arm64-v8a/libclang_rt.ubsan_standalone-aarch64-android.so b/sanitizers/app/src/ubsan/jniLibs/arm64-v8a/libclang_rt.ubsan_standalone-aarch64-android.so index e3c157e9f..44748f8bb 100644 Binary files a/sanitizers/app/src/ubsan/jniLibs/arm64-v8a/libclang_rt.ubsan_standalone-aarch64-android.so and b/sanitizers/app/src/ubsan/jniLibs/arm64-v8a/libclang_rt.ubsan_standalone-aarch64-android.so differ diff --git a/unit-test/app/build.gradle b/unit-test/app/build.gradle index 9c6274706..a9688d2df 100644 --- a/unit-test/app/build.gradle +++ b/unit-test/app/build.gradle @@ -12,6 +12,12 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + ndk { + // junit-gtest and googletest don't currently (August 2025) include + // riscv64 libraries. + abiFilters.remove("riscv64") + } } externalNativeBuild {