This has the same functionality as Tutorial 2, but building the validation layers from the source code inside $NDK_DIR/sources/third_party/vulkan so application could trace code into layers from application. This would help in certain case developers want to see what validation layer is checking for application failed cases, in return app could fix its issues faster. It is also help to discover any potential issues inside validation layers.
Layer source status
- NDK-R12 supports gradle experimental and ndk-build usage model
- NDK-R13 and above removed experimental usage since gradle supports cmake and ndk-build
Earlier version sample uses experimental for ndk-12 source build. Later samples ( including this one) provides cmake and ndk-build build model embedded inside Android Studio (from version 2.2.0 Beta and above ).
There are more than one way to build the layers for debugging purpose:
- add build scripts directly into app's build.gradle
- create a separate empty java lib module to wrap around layers and have app to depend on the lib
- use cmake or ndk-build ( android.mk ) for the above 2 approaches
The former is simpler on scripts, the downside is that, under app inside android studio IDE, you would see all layers are listed as source code together with your own application's source code; and there are 7 + layers with ~10 folders. So your app's src folder would be inside those many folders inside IDE. It won't be a big problem since this is for debug only purpose anyhow
The second approach avoided the "layer source clobbering app" issue mentioned above because it has its own module inside IDE, so application's source under your app would be only application code. The downside is the extra steps to get to this usage:
- Use android to add a new lib module into your application's project (take all of default)
- Add native external build (either cmake or ndk-build) into lib module
- Force lib module ONLY publish debug version of lib so the ONLY debug version is packed into app's APK. It also saves building time: it will not build release version of layers anymore.
the sample here takes second approach: use a separate lib module to deal with validation layer build
- import the sample into your android studio 3.0+
- check local.properties pointing to the right NDK on HOST build machine
- select ndk-build or cmake in layerlib/build.gradle
def USE_CMAKE = 0
. if you are switching back and forth between cmake and ndk-build, before every build after switching, remove intermediate cached build scripts withrm -fr layerlib/.external* layerlib/build app/.external* app/build
known issues:
- windows could not build layers with ndk-build usage model
Windows build extra steps if you see errors while building validation layers, try the following workaround:
- copy your ndk to be directly under C:\
- configure your ndk.dir inside local.properties to your new ndk location this is due to the fact that commend path is above 260 when source is inside ndk