Search code examples
androidfluttervulkan

Excluding Vulkan validation library from Android debug build that uses Flutter


We've recently upgraded to Flutter 3.22.1 and I noticed that our debug build apks have increased by over 240M. There is a shared library in the apk called:

libVkLayer_khronos_validation.so

This appears to be part of Impeller Vulkan validation and only included in the debug build. Our testers are complaining about the size of the debug builds and want it gone. I see flutter options for enabling vulkan validation, but nothing to disable or remove it.

How can I remove this library from my debug Android build?


Solution

  • I think, based on this pull request, that flutter team intentionally made this non-configurable. However, good news is that you can easily configure your gradle build to exclude this library.

    Go to your android/app/build.gradle(.kts) and add this.

    android {
        packagingOptions {
            jniLibs {
                excludes.add("**/libVkLayer_khronos_validation.so")
            }
        }
    }
    

    If you already have an android block in your file (which is likely), simply add the packagingOptions section to it.

    It works, because this library packed in flutter.jar for debug builds, and this setting in gradle is great for this case, when you need to filter native libraries from third-party dependencies