From 1cc2fa22b8e2fccb4136261a1b9457bbc4070f93 Mon Sep 17 00:00:00 2001 From: robland Date: Sun, 31 May 2026 16:22:27 -0500 Subject: [PATCH] Add com.squareup.wire.EnumAdapter compat shim (fixes NoClassDefFoundError on capture) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generated `ltpb` enum adapters (e.g. `ViewPreferences$AspectRatio$ProtoAdapter_AspectRatio`) extend `com.squareup.wire.EnumAdapter` and call its `(Class)` constructor, but `download-libs.sh` pins `wire-runtime` 2.2.0, which ships the reflection-based `RuntimeEnumAdapter` instead — there is no `EnumAdapter` (it is absent from every released wire-runtime 2.0.0-2.2.0 on Maven Central). So those adapters fail to link at runtime and the first capture crashes in the image-save path: java.lang.NoClassDefFoundError: ltpb.ViewPreferences$AspectRatio$ProtoAdapter_AspectRatio at ltpb.ViewPreferences$AspectRatio. at openlight.co.camera.utils.ImageUtil.getAspectRatioValue at openlight.co.camera.managers.capture.CaptureManager$1.onCaptureStarted Restore the small abstract base on top of 2.2.0's `ProtoAdapter`, implemented exactly like `RuntimeEnumAdapter` (an enum is wire-encoded as a VARINT of its value; being in package `com.squareup.wire` lets it call the package-private `ProtoWriter.varint32Size`). The 5 generated enum adapters (AspectRatio, AWBMode, HDRMode, Orientation, SceneMode) then link and the save path completes. Tested by building this repo and installing on a real Light L16: a capture now saves a valid multi-module `.lri` (previously it crashed before writing the file). Co-Authored-By: Claude Opus 4.8 (1M context) --- src/com/squareup/wire/EnumAdapter.java | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/com/squareup/wire/EnumAdapter.java diff --git a/src/com/squareup/wire/EnumAdapter.java b/src/com/squareup/wire/EnumAdapter.java new file mode 100644 index 0000000..e39c720 --- /dev/null +++ b/src/com/squareup/wire/EnumAdapter.java @@ -0,0 +1,37 @@ +package com.squareup.wire; + +import java.io.IOException; + +/** + * Compatibility shim. The stock light_camera APK's generated {@code ltpb} enum adapters + * (e.g. {@code ViewPreferences$AspectRatio$ProtoAdapter_AspectRatio}) extend + * {@code com.squareup.wire.EnumAdapter} and call its {@code (Class)} constructor + override + * {@code fromValue(int)}. That abstract base class is NOT present in any released + * wire-runtime 2.0.0–2.2.0 (which ship the reflection-based {@code RuntimeEnumAdapter} instead), + * so {@code download-libs.sh}'s wire-runtime-2.2.0 lacks it and the adapters fail to link at + * runtime ({@code NoClassDefFoundError} during the first capture's image-save path). + * + * This restores the small abstract base, implemented on top of 2.2.0's {@link ProtoAdapter} + * exactly like {@code RuntimeEnumAdapter}: an enum is wire-encoded as a VARINT of its value. + */ +public abstract class EnumAdapter extends ProtoAdapter { + protected EnumAdapter(Class type) { + super(FieldEncoding.VARINT, type); + } + + /** Subclasses (generated {@code ProtoAdapter_*}) map a proto int back to the enum constant. */ + protected abstract E fromValue(int value); + + @Override public int encodedSize(E value) { + return ProtoWriter.varint32Size(value.getValue()); + } + + @Override public void encode(ProtoWriter writer, E value) throws IOException { + writer.writeVarint32(value.getValue()); + } + + @Override public E decode(ProtoReader reader) throws IOException { + int value = reader.readVarint32(); + return fromValue(value); + } +}