{"record":{"id":"946cc5f74408b022","repo":"JakeWharton/butterknife","slug":"unable-to-find-binding-constructor-for","errorCode":null,"errorMessage":"Unable to find binding constructor for {}","messagePattern":"Unable to find binding constructor for (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"butterknife/src/main/java/butterknife/ButterKnife.java","lineNumber":209,"sourceCode":"      if (debug) Log.d(TAG, \"HIT: Cached in binding map.\");\n      return bindingCtor;\n    }\n    String clsName = cls.getName();\n    if (clsName.startsWith(\"android.\") || clsName.startsWith(\"java.\")\n        || clsName.startsWith(\"androidx.\")) {\n      if (debug) Log.d(TAG, \"MISS: Reached framework class. Abandoning search.\");\n      return null;\n    }\n    try {\n      Class<?> bindingClass = cls.getClassLoader().loadClass(clsName + \"_ViewBinding\");\n      //noinspection unchecked\n      bindingCtor = (Constructor<? extends Unbinder>) bindingClass.getConstructor(cls, View.class);\n      if (debug) Log.d(TAG, \"HIT: Loaded binding class and constructor.\");\n    } catch (ClassNotFoundException e) {\n      if (debug) Log.d(TAG, \"Not found. Trying superclass \" + cls.getSuperclass().getName());\n      bindingCtor = findBindingConstructorForClass(cls.getSuperclass());\n    } catch (NoSuchMethodException e) {\n      throw new RuntimeException(\"Unable to find binding constructor for \" + clsName, e);\n    }\n    BINDINGS.put(cls, bindingCtor);\n    return bindingCtor;\n  }\n}\n","sourceCodeStart":191,"sourceCodeEnd":215,"githubUrl":"https://github.com/JakeWharton/butterknife/blob/fcdebedf3276096db2f51bf6372b849b5a9c75ed/butterknife/src/main/java/butterknife/ButterKnife.java#L191-L215","documentation":"ButterKnife loaded the generated class Foo_ViewBinding via reflection, but Class.getConstructor(Foo.class, View.class) threw NoSuchMethodException — the generated class exists yet does not expose the expected (TargetType, View) constructor. This is a structural mismatch between the butterknife runtime's expectations and the actually generated code, most commonly caused by mixing incompatible versions of the butterknife-compiler (annotation processor) and the butterknife runtime library.","triggerScenarios":"Calling any ButterKnife.bind(...) overload on a class Foo for which Foo_ViewBinding is on the classpath but its constructor signature is not exactly (Foo, View) — e.g. generated by a different (older/newer) ButterKnife version whose constructor takes (Foo, View, Unbinder) or uses a different parameter list, or the generated class was modified/obfuscated so the constructor was renamed or its parameter types changed.","commonSituations":"Upgrading the butterknife runtime without upgrading butterknife-compiler (or vice versa); transitive dependency resolution silently pulling a mismatched butterknife version (check with gradlew dependencies); ProGuard/R8 obfuscating or removing the constructor signature while keeping the class; stale generated sources after migrating between APT and KAPT.","solutions":["Pin butterknife and butterknife-compiler (and butterknife-gradle-plugin if used) to the exact same version in build.gradle, then clean build.","Run ./gradlew app:dependencies --configuration releaseRuntimeClasspath (and debug) to find a transitive ButterKnife version overriding yours; force alignment with a resolutionStrategy or BOM.","Add the official ProGuard keep rules (-keep class **_ViewBinding { <init>(...); }) so R8 does not strip or alter the generated constructor.","If mismatch persists, inspect app/build/generated/source/apt(或kapt)/.../Foo_ViewBinding.java to see the actual constructor signature and confirm which processor version generated it."],"exampleFix":"// before: version skew produces Foo_ViewBinding without (Foo, View) ctor\n// java.lang.RuntimeException: Unable to find binding constructor for com.example.Foo\nimplementation 'com.jakewharton:butterknife:10.2.3'\nannotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0' // stale!\n\n// after: aligned versions + clean build\nimplementation 'com.jakewharton:butterknife:10.2.3'\nannotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'\n// then: ./gradlew clean assembleDebug","handlingStrategy":"validation","validationCode":"// Before bind, confirm the generated class has the exact (Target, View) constructor\npublic static boolean hasValidBindingConstructor(Class<?> targetClass) {\n  String name = targetClass.getName();\n  if (name.startsWith(\"android.\") || name.startsWith(\"java.\") || name.startsWith(\"androidx.\")) {\n    return true; // framework classes: bind() returns Unbinder.EMPTY, no error\n  }\n  try {\n    Class<?> bindingClass = targetClass.getClassLoader().loadClass(name + \"_ViewBinding\");\n    bindingClass.getConstructor(targetClass, View.class);\n    return true;\n  } catch (NoSuchMethodException e) {\n    return false; // version-skewed or altered generated code\n  } catch (ClassNotFoundException e) {\n    return true; // no generated class: bind() falls back to superclass/EMPTY\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  unbinder = ButterKnife.bind(this);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to find binding constructor\")) {\n    // structural mismatch: generated class exists but ctor signature differs ->\n    // almost always butterknife compiler/runtime version skew\n    throw new IllegalStateException(\"ButterKnife version mismatch: align butterknife and butterknife-compiler\", e);\n  }\n  throw e;\n}","preventionTips":["Align butterknife runtime and compiler versions in every module; use a version catalog or BOM to enforce it.","Review ./gradlew dependencies output after library updates for transitive ButterKnife versions.","Keep **_ViewBinding classes and constructors in ProGuard/R8 rules when minification is on.","Migrate to View Binding when possible — it is compile-time and immune to reflection/ProGuard mismatch failures."],"tags":["butterknife","android","annotation-processing","version-mismatch","reflection","proguard"],"backgroundTag":null,"analyzedSha":"fcdebedf3276096db2f51bf6372b849b5a9c75ed","analyzedAt":"2026-08-14T10:13:55.083Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}