Skip to content

Update AGP, NDK, CMake, and other dependencies #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Tutorial Samples
================
A set of samples to illustrate Vulkan API on Android with Android Studio
To build on windows for tutorial02/03, copy/install ndk-r12 ( or better ) to a directory close to root dir ( C: ) to workaround command path 260 character limit issue; see tutorial02/03's build.gradle for details. To Build samples:
- Inside Andriod, menu File --> New --> Import Project
- Find your sample's build.gradle and open it
This will force andrioid studio to create local.properties file to config your SDK and NDK location; if you see error during importing, open local.properties file and correct the NDK and SDK location, then re-sync.
A set of samples to illustrate Vulkan API on Android with Android Studio.

To build the samples:
- Inside Android Studio, use File --> New --> Import Project
- Find your sample's directory or `build.gradle` file, and open it

This will force Andrioid Studio to create local.properties file to config your SDK location. If you see
an Android SDK error during importing, you can open local.properties file and correct the SDK path.

Other Resources:
Additional Android Studio/NDK samples:
Expand All @@ -31,19 +34,25 @@ Refer to README.md under its directory

Pre-requisites
--------------
- A device running Android 7.0 (API level 24) or higher
- [Android Studio 3.0](https://developer.android.com/studio/index.html) or higher
- Android NDK
- A device running Android 8.0 (API level 26) or higher
- [Android Studio Jellyfish](https://developer.android.com/studio/index.html) or higher
- Android NDK r25c
* [NDK](https://developer.android.com/ndk/downloads/index.html)
* SDK with the latest cmake package
- CMake 3.22.1 from Android SDK

Test Matrix
------------
| Andrid Studio Version | cmake in SDK| NDK | device |
|-----------------------|-------------|----------|---------|
| 3.0.0 | 3.6.4111459 | NDK-r16 | Pixel XL|
| Android Studio | CMake | NDK | Device | API Level |
|-----------------------|-------------|----------|-----------------|-----------|
| Jellyfish 2023.3.1 | 3.22.1 | r25c | Pixel 7 Pro | 34 |
| Jellyfish 2023.3.1 | 3.22.1 | r25c | x86_64 Emulator | 34 |


Known Issues
------------

Known Issue:
On Windows, if you hit the maximum 260 character path limit issue, copy/install the NDK
to a directory close to the file system root (e.g., `C:`).

Getting Started
---------------
Expand All @@ -52,7 +61,7 @@ Getting Started

License
-------
Copyright 2016 Google, Inc.
Copyright 2024 Google, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
Expand Down
16 changes: 8 additions & 8 deletions tutorial01_load_vulkan/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
ndkVersion '22.1.7171670'
compileSdkVersion 34
ndkVersion '25.2.9519653'

defaultConfig {
applicationId "com.android.example.vulkan.tutorials.one"
minSdkVersion 24
targetSdkVersion 31
minSdkVersion 26
targetSdkVersion 34

versionCode 272
versionName "1.1.0"
externalNativeBuild {
cmake {
abiFilters "armeabi-v7a", 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a', 'x86_64'
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
}
}
}
externalNativeBuild {
cmake {
version '3.18.1'
version '3.22.1'
path 'src/main/cpp/CMakeLists.txt'
}
}
Expand All @@ -44,6 +44,6 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.games:games-activity:1.1.0"
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation "androidx.games:games-activity:1.2.2"
}
2 changes: 1 addition & 1 deletion tutorial01_load_vulkan/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Sep 24 15:15:23 TRT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
17 changes: 8 additions & 9 deletions tutorial02_prebuild_layers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

Demonstrate how to use validation layers prebuilt from [Validation layer repo][1]

## Pre-requirement:
---------------
1. Download prebuilt validation layer android-binaries-*.zip from [Khronos repo][1]
1. unzip to $this-project-root/vvl-libs
This sample automatically downloads prebuilt validation layer zip from [Khronos repo][1],
unzips it, and adds the validation layer library to the project's jniLibs.

## Added steps from previous example
1. Use vulkan wrappers in common/vulkan_wrapper directory.
1. Add the validation layer into gradle build to pack it into apk.
1. (Optional but nice to have)Confirm the validation layer "VK_LAYER_KHRONOS_validation" is available with `vkEnumerateInstanceLayerProperties()`.
1. Enable the validation layer and "VK_EXT_debug_report" when creating instance.
1. Register debug callback implemented in "VK_EXT_debug_report" with vkCreateDebugReportCallbackEXT(). Note that application could also use "VK_EXT_debug_utils" implemented in the validatio layer.
1. Add the validation layer into gradle build to pack it into APK.
1. (Optional but nice to have) Confirm the validation layer `VK_LAYER_KHRONOS_validation` is available with `vkEnumerateInstanceLayerProperties()`.
1. Enable the validation layer and `VK_EXT_debug_report` when creating instance.
1. Register debug callback implemented in `VK_EXT_debug_utils` with `pfnCreateDebugUtilsMessengerEXT()`. Note that on some devices it can use `VK_EXT_debug_report` instead.

# Verification
Planted error: this sample sets [`VkDeviceQueueCreateInfo::pQueuePriorities`][2](https://github.com/googlesamples/android-vulkan-tutorials/blob/master/tutorial02_prebuild_layers/app/src/main/jni/main.cpp#L190) to nullptr,
Planted error: this sample sets [`VkDeviceQueueCreateInfo::pQueuePriorities`][2](https://github.com/googlesamples/android-vulkan-tutorials/blob/master/tutorial02_prebuild_layers/app/src/main/jni/main.cpp#L190) to `nullptr`,
which will trigger validation layers to notify us from registered callback function
`vkDebugReportCallbackEX_impl();` putting a breakpoint with Android Studio, observe
the breakpoint being triggered.
Expand All @@ -24,6 +22,7 @@ In logcat, you would see the error message like:
```
E/Vulkan-Debug-Message:: Validation -- Validation Error: [ VUID-VkDeviceQueueCreateInfo-pQueuePriorities-parameter ] Object 0: VK_NULL_HANDLE, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xd6d720c6 | vkCreateDevice: required parameter pCreateInfo->pQueueCreateInfos[0].pQueuePriorities specified as NULL. The Vulkan spec states: pQueuePriorities must be a valid pointer to an array of queueCount float values (https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#VUID-VkDeviceQueueCreateInfo-pQueuePriorities-parameter)
```

## Additional References
- [Validation layer history][3]
[1]:https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/latest
Expand Down
12 changes: 6 additions & 6 deletions tutorial02_prebuild_layers/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ apply plugin: 'com.android.application'

// Download validation layers from
// https://github.com/KhronosGroup/Vulkan-ValidationLayers
ext.vvl_version='1.3.231.1'
ext.vvl_version='1.3.290.0'
apply from: 'download_vvl.gradle'

// This project's build scripts follows
android {
compileSdkVersion 33
ndkVersion '22.1.7171670'
compileSdkVersion 34
ndkVersion '25.2.9519653'
defaultConfig {
applicationId "com.android.example.vulkan.tutorials.two"
minSdkVersion 26
targetSdkVersion 31
targetSdkVersion 34
versionCode 272
versionName "1.1.0"
externalNativeBuild {
cmake {
abiFilters "armeabi-v7a", 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a', 'x86_64'
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
}
}
}
externalNativeBuild {
cmake {
version '3.18.1'
version '3.22.1'
path 'src/main/cpp/CMakeLists.txt'
}
}
Expand Down
6 changes: 3 additions & 3 deletions tutorial02_prebuild_layers/app/download_vvl.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'com.android.application'
*/

// get tjhe validation layer version.
def VVL_VER = "1.3.231.1"
def VVL_VER = "1.3.290.0"
if (ext.has("vvl_version")) {
VVL_VER = ext.vvl_version
}
Expand All @@ -29,7 +29,7 @@ def VVL_SO_NAME = "libVkLayer_khronos_validation.so"

// download the release zip file to ${VVL_LIB_ROOT}/
task download {
def VVL_ZIP_NAME = "releases/download/sdk-${VVL_VER}/android-binaries-${VVL_VER}.zip"
def VVL_ZIP_NAME = "releases/download/vulkan-sdk-${VVL_VER}/android-binaries-${VVL_VER}.zip"
mkdir "${VVL_LIB_ROOT}"
def f = new File("${VVL_LIB_ROOT}/android-binaries-${VVL_VER}.zip")
new URL("${VVL_SITE}/${VVL_ZIP_NAME}")
Expand All @@ -42,7 +42,7 @@ task unzip(dependsOn: download, type: Copy) {
into file("${VVL_JNILIB_DIR}")
}
android.sourceSets.main.jniLibs {
srcDirs += ["${VVL_JNILIB_DIR}"]
srcDirs += ["${VVL_JNILIB_DIR}/android-binaries-${VVL_VER}"]
}

// add vvl download as an application dependency.
Expand Down
2 changes: 1 addition & 1 deletion tutorial02_prebuild_layers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.android.tools.build:gradle:7.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Dec 09 10:29:26 PST 2022
#Tue Sep 24 15:14:08 TRT 2024
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
46 changes: 22 additions & 24 deletions tutorial03_traceable_layers/README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
# Tutorial 03 - traceable_layers

This has the same functionality as [Tutorial 2](../tutorial02_prebuild_layers), but building the validation layers
from the Khronos Group Validation Layer source code hosted on [the github repo](https://github.com/KhronosGroup/Vulkan-ValidationLayers.git).

The benefit is:
- you could trace into validation layers.
- you could observe the detailed status when validation layer finds issues in your app.
- You can peek/step into validation layers.
- You can observe the detailed status when validation layer finds issues in your app.

Validation layers are stable now, this should be a good help to developers who likge to know
more about validation layers inside.
This can be useful for developers who want to know more about validation layers.

# Background
Layer source status:
- For NDK version <= r21, there are multiple layers for Android; NDK keeps a snapshot of layer source code and the binaries
- For NDK22 layers are consolidated into one layer: VkLayer_khronos_validation; NDK keeps a snapshot of layer source code and the binary
- For NDK version >= r23, layer source and binary are not available anymore.

We recommend developers to get the validation layer source and binary releases directly from
Building validation layers from sources currently requires NDK r25c or newer.

Developers should get the validation layer source from
[the github repo](https://github.com/KhronosGroup/Vulkan-ValidationLayers.git).


# Build Instructions
In this sample, the validation layers is wrapped into a gradle library module called "layerlib", it is a dependent module to application
code(to force it build before app).The validation layer source code needs to be pulled in on command line before building the sample:

In this sample, the validation layers is wrapped into a gradle library module called `layerlib`. The `app`
module depends on this `layerlib` module.

The validation layer source code needs to be pulled in on command line before building the sample. Steps:

1. cd tutorial03_traceable_layers/layerlib
2. git clone --recursive https://github.com/KhronosGroup/Vulkan-ValidationLayers.git
3. cd Vulkan-ValidationLayers/build-android
4. ./update_external_sources_android.sh --no-build
(use the update_external_sources_android.bat for Windows OS)
5. Now, at this point, open this sample with Android Studio with "Open an Existing Project" option
6. Build the project, and start debugging(Run > Debug App). It takes about 20 minutes to build layers, so be patient

Once app triggers validation layer assert(embedded on purpose inside this sample in the app), you could see the stack frames
inside Studio IDE., inside the debug window, you would see all validation layer variables when the app error is validated.
3. Make sure the `cmake` binary is on your `PATH` environment variable.
4. Open this sample with Android Studio with "Open an Existing Project" option
5. Sync the project with Gradle Files. This can take 3-5 minutes to sync.
6. Build the project, and start debugging (Run > Debug App). It can take 5-10 minutes to build.

This sample is not tested on windows, it should work.
Once the app triggers validation layer assert (embedded on purpose inside this sample in the app), you can see the stack frames
in the Android Studio IDE debugger. You can also step into the validation layer, and check the values of all variables.

## future work
- Automically pull the source code automatically in gradle, but gradle's 'ndkBuild path' is evaluated before source code pulling,
hence errors out, need help to get it done.
- automatically run update_external_sources_android.sh. probably needs a gradle task to do it.
## Future Work
- Automatically pull the source code automatically in Gradle.

# Screenshot
![screenshot](screenshot.png)
Expand Down
16 changes: 8 additions & 8 deletions tutorial03_traceable_layers/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
ndkVersion '22.1.7171670'
compileSdkVersion 34
ndkVersion '25.2.9519653'

defaultConfig {
applicationId "com.android.example.vulkan.tutorials.three"
minSdkVersion 24
targetSdkVersion 31
minSdkVersion 26
targetSdkVersion 34
versionCode = 272
versionName = "1.1.0"
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
ndk.abiFilters 'arm64-v8a', 'x86_64'
externalNativeBuild.cmake.arguments '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_STL=c++_static'
}
Expand All @@ -34,7 +34,7 @@ android {
}
externalNativeBuild {
cmake {
version '3.18.1'
version '3.22.1'
path = 'src/main/cpp/CMakeLists.txt'
}
}
Expand All @@ -45,6 +45,6 @@ android {

dependencies {
implementation project(path: ':layerlib')
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.games:games-activity:1.1.0"
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation "androidx.games:games-activity:1.2.2"
}
2 changes: 1 addition & 1 deletion tutorial03_traceable_layers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 28 22:36:34 PDT 2021
#Tue Sep 24 15:20:37 TRT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
Loading