diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 534bfb1df1ef..6cc377820210 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -331,6 +331,40 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks)
 /*
  * Return static information for the camera.
  */
+std::pair<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()
+{
+	/*
+	 * \todo Keep this in sync with the actual number of entries.
+	 * Currently: 50 entries, 647 bytes of static metadata
+	 */
+	std::pair<uint32_t, uint32_t> metadataSize;
+	metadataSize.first = 50;
+	metadataSize.second = 647;
+
+	/*
+	 * Calculate space occupation in bytes for dynamically built metadata
+	 * entries.
+	 */
+
+	/* std::forward_list does not provide a size() method :( */
+	for (const auto &entry : streamConfigurations_) {
+		/* Just please the compiler, otherwise entry is not used. */
+		switch (entry.androidScalerCode) {
+		default:
+			break;
+		}
+
+		/*
+		 * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS
+		 * 1 32bits integer for ANDROID_SCALER_AVAILABLE_FORMATS
+		 * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS
+		 */
+		metadataSize.second += 52;
+	}
+
+	return metadataSize;
+}
+
 const camera_metadata_t *CameraDevice::getStaticMetadata()
 {
 	if (staticMetadata_)
@@ -341,12 +375,8 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
 	 * example application, but a real camera implementation will require
 	 * more.
 	 */
-
-	/*
-	 * \todo Keep this in sync with the actual number of entries.
-	 * Currently: 50 entries, 666 bytes
-	 */
-	staticMetadata_ = new CameraMetadata(50, 700);
+	const std::pair<uint32_t, uint32_t> sizes = calculateStaticMetadataSize();
+	staticMetadata_ = new CameraMetadata(sizes.first, sizes.second);
 	if (!staticMetadata_->isValid()) {
 		LOG(HAL, Error) << "Failed to allocate static metadata";
 		delete staticMetadata_;
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 95bd39f590ab..f22a6e3e6c28 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -10,6 +10,7 @@
 #include <forward_list>
 #include <map>
 #include <memory>
+#include <utility>
 
 #include <hardware/camera3.h>
 
@@ -69,6 +70,7 @@ private:
 	};
 
 	int initializeFormats();
+	std::pair<uint32_t, uint32_t> calculateStaticMetadataSize();
 	void notifyShutter(uint32_t frameNumber, uint64_t timestamp);
 	void notifyError(uint32_t frameNumber, camera3_stream_t *stream);
 	std::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,
