{"record":{"id":"0d68aa632c485b78","repo":"unoplatform/uno","slug":"unable-to-find-staticlayout-constructor","errorCode":null,"errorMessage":"Unable to find StaticLayout constructor.","messagePattern":"Unable to find StaticLayout constructor\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Uno.UI.BindingHelper.Android/Uno/UI/UnoStaticLayoutBuilder.java","lineNumber":44,"sourceCode":"\t\tcatch(Exception e) { \n\t\t\tLog.e(\"UmbrellaStaticLayoutBuilder\", \"Failed to initialize StaticLayout builder. \" + e.toString());\n\t\t}\n\t}\n\n\tprivate static void buildStaticLayoutReflection() throws ClassNotFoundException, InstantiationException, Exception\n\t{\n\t\tClass staticLayoutClass = Class.forName(\"android.text.StaticLayout\");\n\t\tConstructor[] ctors = staticLayoutClass.getDeclaredConstructors();\n\n\t\tfor(int i=0; i<ctors.length; i++) {\n\t\t\tif(ctors[i].getParameterTypes().length == 13){\n\t\t\t\tstaticLayoutConstructor = ctors[i];\n\t\t\t\tstaticLayoutConstructor.setAccessible(true);\n\t\t\t}\n\t\t}\n\n\t\tif(staticLayoutConstructor == null) {\n\t\t\tthrow new Exception(\"Unable to find StaticLayout constructor.\");\n\t\t}\n\t}\n\n\tprivate static void buildTextDirection() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {\n\t\tif (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {\n\t\t\ttextDirectionHeuristic = TextDirectionHeuristics.FIRSTSTRONG_LTR;\n\t\t}\n\t\telse {\n\t\t\t// This is required because this class was not exposed until API 18 but available before.\n\t\t\tClass textDirectionHeuristicsClass = java.lang.Class.forName(\"android.text.TextDirectionHeuristics\");\n\t\t\tField firstStrongField = textDirectionHeuristicsClass.getField(\"FIRSTSTRONG_LTR\");\n\n\t\t\ttextDirectionHeuristic = (TextDirectionHeuristic)firstStrongField.get(null);\n\t\t}\n\t}\n\n\tpublic static StaticLayout Build(\n\t\tCharSequence source,","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/Uno.UI.BindingHelper.Android/Uno/UI/UnoStaticLayoutBuilder.java#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Raise minSdkVersion to at least API 11+ where the 13-param StaticLayout constructor exists.","If using ProGuard/R8, add a keep rule for android.text.StaticLayout constructors: -keep class android.text.StaticLayout { <init>(...); }.","Check the target device/emulator API level — this is a platform-version-specific reflection issue."],"exampleFix":"// before: runs on old API where constructor is missing\n// UnoStaticLayoutBuilder static initializer throws\n\n// after: ensure minSdkVersion is adequate\n// In csproj or AndroidManifest:\n// <uses-sdk android:minSdkVersion=\"16\" />\n// And add ProGuard keep rule if shrinking:\n// -keep class android.text.StaticLayout { <init>(*); }","handlingStrategy":"validation","validationCode":"// Validate API level before relying on the reflected constructor\nif (android.os.Build.VERSION.SDK_INT < 11) {\n    // StaticLayout 13-param constructor may not exist — use a fallback\n}","typeGuard":null,"tryCatchPattern":"// The initializer catches the exception and logs it (line 26-28).\n// Check LogCat for 'UmbrellaStaticLayoutBuilder' errors at startup.","preventionTips":["Set minSdkVersion to a level where the 13-param StaticLayout constructor exists.","Add ProGuard/R8 keep rules for android.text.StaticLayout if shrinking is enabled.","Monitor LogCat for 'UmbrellaStaticLayoutBuilder' initialization failures."],"tags":["android","reflection","text-layout","static-layout","java","version-compat"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}