unoplatform/uno · critical · Exception

Unable to find StaticLayout constructor.

Error message

Unable to find StaticLayout constructor.

What it means

Thrown by UnoStaticLayoutBuilder.buildStaticLayoutReflection during static initialization when no constructor of android.text.StaticLayout has exactly 13 parameters. The builder uses reflection to find the legacy 13-argument StaticLayout constructor. On certain Android API levels the constructor signature differs, so the reflection scan finds no match.

Source

Thrown at src/Uno.UI.BindingHelper.Android/Uno/UI/UnoStaticLayoutBuilder.java:44

		catch(Exception e) { 
			Log.e("UmbrellaStaticLayoutBuilder", "Failed to initialize StaticLayout builder. " + e.toString());
		}
	}

	private static void buildStaticLayoutReflection() throws ClassNotFoundException, InstantiationException, Exception
	{
		Class staticLayoutClass = Class.forName("android.text.StaticLayout");
		Constructor[] ctors = staticLayoutClass.getDeclaredConstructors();

		for(int i=0; i<ctors.length; i++) {
			if(ctors[i].getParameterTypes().length == 13){
				staticLayoutConstructor = ctors[i];
				staticLayoutConstructor.setAccessible(true);
			}
		}

		if(staticLayoutConstructor == null) {
			throw new Exception("Unable to find StaticLayout constructor.");
		}
	}

	private static void buildTextDirection() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
		if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
			textDirectionHeuristic = TextDirectionHeuristics.FIRSTSTRONG_LTR;
		}
		else {
			// This is required because this class was not exposed until API 18 but available before.
			Class textDirectionHeuristicsClass = java.lang.Class.forName("android.text.TextDirectionHeuristics");
			Field firstStrongField = textDirectionHeuristicsClass.getField("FIRSTSTRONG_LTR");

			textDirectionHeuristic = (TextDirectionHeuristic)firstStrongField.get(null);
		}
	}

	public static StaticLayout Build(
		CharSequence source,

View on GitHub (pinned to 0418340488)

Solutions

  1. Raise minSdkVersion to at least API 11+ where the 13-param StaticLayout constructor exists.
  2. If using ProGuard/R8, add a keep rule for android.text.StaticLayout constructors: -keep class android.text.StaticLayout { <init>(...); }.
  3. Check the target device/emulator API level — this is a platform-version-specific reflection issue.

Example fix

// before: runs on old API where constructor is missing
// UnoStaticLayoutBuilder static initializer throws

// after: ensure minSdkVersion is adequate
// In csproj or AndroidManifest:
// <uses-sdk android:minSdkVersion="16" />
// And add ProGuard keep rule if shrinking:
// -keep class android.text.StaticLayout { <init>(*); }
Defensive patterns

Strategy: validation

Validate before calling

// Validate API level before relying on the reflected constructor
if (android.os.Build.VERSION.SDK_INT < 11) {
    // StaticLayout 13-param constructor may not exist — use a fallback
}

Try / catch

// The initializer catches the exception and logs it (line 26-28).
// Check LogCat for 'UmbrellaStaticLayoutBuilder' errors at startup.

Prevention

When it happens

Trigger: Running on an Android version where android.text.StaticLayout does not expose a constructor with exactly 13 parameters. This can happen on very old API levels (pre-API 11 where the constructor count differs) or potentially on future API levels if Google changes the constructor set.

Common situations: Running the app on an emulator or device with an Android version whose StaticLayout class lacks the 13-param constructor; targeting a minSdkVersion that is too low for the expected constructor; obfuscation tools (ProGuard/R8) stripping constructors.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/0d68aa632c485b78. Report an issue: GitHub.