From 95a977e12e1a3163c2fca7dff4648555144e69f0 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Fri, 14 Aug 2026 16:37:28 +0200 Subject: [PATCH] Reduce Android AAR size with header-only Prefab (#4483) --- include/mbgl/style/layers/custom_layer_host.hpp | 6 +++++- platform/android/MapLibreAndroid/build.gradle.kts | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/mbgl/style/layers/custom_layer_host.hpp b/include/mbgl/style/layers/custom_layer_host.hpp index 6561be1aa..4abe092a3 100644 --- a/include/mbgl/style/layers/custom_layer_host.hpp +++ b/include/mbgl/style/layers/custom_layer_host.hpp @@ -1,10 +1,14 @@ #pragma once -#include #include #include namespace mbgl { + +namespace gfx { +class Context; +} // namespace gfx + namespace style { class CustomLayerHost { diff --git a/platform/android/MapLibreAndroid/build.gradle.kts b/platform/android/MapLibreAndroid/build.gradle.kts index 5a645ac39..eef6ee1d1 100644 --- a/platform/android/MapLibreAndroid/build.gradle.kts +++ b/platform/android/MapLibreAndroid/build.gradle.kts @@ -204,7 +204,7 @@ android { prefab { create("maplibre") { headers = "../prefab-headers" - libraryName = "libmaplibre" + headerOnly = true } } @@ -240,6 +240,16 @@ tasks.configureEach { } } +// AGP 9.1.1 still adds the native build output to the AAR even when the Prefab module is +// declared header-only. Keep the header-only metadata and omit that redundant unstripped copy. +tasks.withType().configureEach { + if (name.startsWith("bundle") && name.endsWith("Aar")) { + // The Prefab artifact is added under a `prefab/` destination by a nested copy spec, + // so its paths are still relative to the Prefab root when exclusions are evaluated. + exclude("modules/maplibre/libs/**") + } +} + configurations { getByName("implementation") { exclude(group = "commons-logging", module = "commons-logging")